{"id":1079,"hash":"9ab68624b00dcf2ed051f65923bf5c168e5f85c6896361eef4408286905a70e8","pattern":"UnicodeEncodeError: &#39;ascii&#39; codec can&#39;t encode character at special name","full_message":"My python (ver 2.7) script is running well to get some company name from local html files but when it comes to some specific country name, it gives this error \"UnicodeEncodeError: 'ascii' codec can't encode character\"\n\nSpecially getting error when this company name comes\n\nCompany Name: Kühlfix Kälteanlagen Ing.Gerhard Doczekal & Co. KG\n\nThe link cannot be processed\n\nTraceback (most recent call last): \n  File \"C:\\Python27\\Process2.py\", line 261, in <module>\n    flog.write(\"\\nCompany Name: \"+str(pCompanyName))\nUnicodeEncodeError: 'ascii' codec can't encode character u'\\xfc' in position 9: ordinal not in range(128)\n\nError gives in this line of code: \n\nif companyAlreadyKnown == 0:\n   for hit in soup2.findAll(\"h1\"):\n       print \"Company Name: \"+hit.text\n       pCompanyName = hit.text\n       flog.write(\"\\nCompany Name: \"+str(pCompanyName))\n       companyObj.setCompanyName(pCompanyName)","ecosystem":"pypi","package_name":"unicode","package_version":null,"solution":"Try setting the system default encoding as utf-8 at the start of the script, so that all strings are encoded using that.\n\nExample -\n\nimport sys\nreload(sys)\nsys.setdefaultencoding('utf-8')\n\nThe above should set the default encoding as utf-8 .","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/31137552/unicodeencodeerror-ascii-codec-cant-encode-character-at-special-name","votes":71,"created_at":"2026-04-19T04:52:18.512787+00:00","updated_at":"2026-04-19T04:52:18.512787+00:00"}