Search code examples
pythoncharacter-encodingpython-requestshttp-request

Unknown encoding: idna in Python Requests


I'm using Python Requests. All works great but today I get this strange error:

[...]
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/requests/models.py", line 321, in full_url
    netloc = netloc.encode('idna').decode('utf-8')
LookupError: unknown encoding: idna

Any ideas what could be wrong? I'm using Python 2.7.2 from brew.


Solution

  • Try adding:

    import encodings.idna
    

    in various places to sift out other errors. I ran into this same problem working on a port of python to a new platform. We had only partial library support and unicodedata was missing which was causing imports of the idna module to fail. Once we ported unicodedata this error went away.