apipython-requestslongtext

Python API requests.post and long strings


does anyone has experience with the requests.post command in python? I have an issue with an api using this command, but only with very long strings as input data (i.e. within the json input of the 'params' argument). For shorter strings, however, the command works just fine. Does anyone know if requests.post has any restrictions with respect to the length of an input string?

edit: The code looks as follows:

freetext  = "very long text"
freetextbody = {"free_text": freetext} 
response.textsearch = requests.post(url, params = freetextbody, headers=headeruser)

However, the API is not open access. So I guess code really does not help a lot here. The thing is that the string 'freetext' contains a very long text which results in an error:

ConnectionError: ('Connection aborted.', BadStatusLine('<html>\r\n',)). 

The error is on my side rather than on the API provider's side, i.e. either python, the requests.post or something else seems not to work. Unfortunately, I have no clue what the issue here is.

Thanks for any help!


Solution

  • With params, your free_text is actually passed as query string. Use data to post it as form data. The query string is size-limited server-side to some arbitrary long value. This is not a limitation of requests.