Mar 27, 2020 02:14 PM
Hello
I have a table in Airtable that I fill with data from a Python dataframe - pandas
I run code on a jupyter notebook and it works normally:
from airtable import Airtable
table = Airtable(api_key = "",
base_key ="",
table_name ="")
for num, row in posts_deputados.iterrows():
dicio = {'post_id': row['post_id'],
'text': row['text'],
'post_text': row['post_text'],
'shared_text': row['shared_text'],
'time': row['time'],
'image': row['image'],
'likes': row['likes'],
'comments': row['comments'],
'shares': row['shares'],
'post_url': row['post_url'],
'link': row['link'],
'cpf': row['cpf'],
'post_text_copia': row['post_text_copia'],
'ANO_ELEICAO': row['ANO_ELEICAO'],
'SG_UF': row['SG_UF'],
'DS_CARGO': row['DS_CARGO'],
'SQ_CANDIDATO': row['SQ_CANDIDATO'],
'NM_CANDIDATO': row['NM_CANDIDATO'],
'NM_URNA_CANDIDATO': row['NM_URNA_CANDIDATO'],
'NR_CPF_CANDIDATO': row['NR_CPF_CANDIDATO'],
'SG_PARTIDO': row['SG_PARTIDO'],
'DS_SIT_TOT_TURNO': row['DS_SIT_TOT_TURNO']}
table.insert(dicio)
But this same code when I run a script within Sublime Text appears this error:
HTTPError: 422 Client Error: Unprocessable Entity for url: https://api.airtable.com/v0/appQ47u0M1wtA1JAc/Table 1 (Decoded URL) [Error: {'type': 'INVALID_REQUEST_BODY', 'message': 'Could not parse request body'}]
Please, is there any incompatibility between Airtable and Sublime Text?
Mar 27, 2020 02:20 PM
Is it possible for you to perform URL encoding on the target URL in you Sublime script? I could be wrong, but it looks like your issue is stemming from the /Table 1
portion of your URL, which contains a whitespace
character. For the URL to process properly, I think that needs to be encoded as such: /Table%201
.
Alternatively, you could ensure that none of your Table names in your Airtable base have any whitespace characters in their names :man_shrugging:t2:
Mar 27, 2020 02:28 PM
Thanks @Jeremy_Oglesby
I have now changed the name to “Table1”
On the jupyter notebook works
But in Sublime Text the same error continues
Mar 27, 2020 02:39 PM
Ah ya… I guess the error is complaining about the request body, not the URL itself.
Not sure what’s going on then, that different systems are producing different request bodies out of the same script…
Mar 27, 2020 05:22 PM
Recommendation - downsize the request to a single text field to see if something in the payload is causing this error message.
Also, consider the possibility that Sublime Text is inappropriately re-stringifying or failing to stringify dicio
when it performs the POST.