October 22, 2024
Chicago 12, Melborne City, USA
python

get request throws UnicodeEncodeError in Python but works well in Postman


I’m making a get request to a url to get back a json file. This works fine in postman. Converted the code to python where I get this error:
UnicodeEncodeError: ‘latin-1’ codec can’t encode characters in position 0-5: ordinal not in range(256)

def get_pois():
    url = "https://example.com/iv/api/site/2086220822020250/pois?lang=en"
    payload = {}
    headers = {
        'Accept': 'application/json',
        'X-Authorization': get_token(),
        'Authorization': '••••••'
    }
    response = requests.request("GET", url, headers=headers, data=payload, verify=False)
    print(response.text)

I tried to change lang from en to en_US.utf8
I tried to add ‘Content-Type’: ‘text/html; charset=utf-8’
I tried to encode but the error seems to come with the request so I don’t know where I can encode something.

Probably the problem comes with the return of the body because there are url’s in the returning json.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video