Post unicode string to web service using Python Requests library Post unicode string to web service using Python Requests library python-3.x python-3.x

Post unicode string to web service using Python Requests library


It is not clear what content type json-tagger.herokuapp.com expects (the examples are contradictory). You could try to post the data as text:

#!/usr/bin/env pythonimport requests  # pip install requestsr = requests.post(url,                  data=text.encode('utf-8'),                  headers={'Content-type': 'text/plain; charset=utf-8'})print(r.json())

Or you could try to send it as application/x-www-form-urlencoded:

#!/usr/bin/env pythonimport requests  # pip install requestsr = requests.post(url, data=dict(data=text))print(r.json())

The server may reject both, accept both, accept one but not the other, or expect some other format (e.g., application/json), etc.