0

I'm currently writing a REST API Data Grabber in Python, which should save some JSON data into a .csv file. It's writing 10.000 of lines of data, but sometimes the program stops and returns this Error

File "C:\***\PycharmProjects\REST_API_Data_Grabber\lib\Export.py", line 156, in writeClientsTableFromIds
csvWriter.writerow([client.get('Id', emptyReplace), function, zipCode])
File "C:\***\Python\Python35\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\x81' in position 23: character maps to <undefined>

Could anyone help me, please?

EDIT: the JSON which produces the error contains:

"Function": "Blumenladen, Gesch?ftsf\u0081hrer",
"Group": "",
"GroupId": 493,

and I need to replace it, but I can't make it.

friaN1337
  • 3
  • 3
  • Try put `.encode("utf-8")` where you are loading a data from json – amarynets Aug 30 '17 at 12:08
  • csvWriter.writerow([client.get('Id', emptyReplace), function.encode("utf-8"), zipCode]) this doesn't work – friaN1337 Aug 30 '17 at 12:16
  • If anyone got this problem, here is my fix method: def replacer(string): return re.sub(r'[^\x00-\x7f]', r' ', string) – friaN1337 Aug 30 '17 at 15:07
  • It's not a clear solution. Can you give some code snippet where you read from json and paste to csv? I tried paste `Gesch?ftsf\u0081hrer` and all works fine – amarynets Aug 30 '17 at 19:34
  • @marni No, if I try to write a row with the data "Gesch?ftsf\u0081hrer" it crashed with the error above – friaN1337 Aug 31 '17 at 12:48

0 Answers0