1

I use aiohttp to make request to my url, but I don`t know why this error occurs!!!!!

async def get_location_data(url):
    try:
        async with aiohttp.ClientSession() as session:
            async with session.get(url) as response:
                data = await response.json() 
                return data 
    except Exception:
        return None

while I get the response and I want to change items of my list, this error happens:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-4: ordinal not in range(128)

I have searched so much about it, some people said that I should use response.text(encoding="utf-8) or response.json(encoding="utf-8)

How can I fix this error?

1
  • stack trace would be useful Commented May 14, 2018 at 6:00

1 Answer 1

3

As other people have said, use await response.json(encoding="utf-8").

Sign up to request clarification or add additional context in comments.

1 Comment

I tried again and I found because of some configurations in the server of our company couldn`t get unicode strings from json response. Thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.