0

My code (everything is imported correctly):

def getTableData(a,b):
    requestUrl = 'https://examplesite.com/docs/' + str(a) + '-sitrep-' + str(b) + '-doc.pdf'
    r = requests.get(requestUrl)
    data = r.text
    save_path = "C:/Users/myname/OneDrive/desktop/filename/pdf"
    file_name = str(a) + str(b)
    os.path.join(save_path,file_name+".pdf")
    f = open(file_name + '.pdf','w')
    f.write(data)
    f.close()



a = 20200422
b = 93
while(flag):
    a += 1
    b += 1
    getTableData(a,b)
    time.sleep(600)

However, I get the error:

  File "tabledata.py", line 35, in <module>
    getTableData(a,b)
  File "tabledata.py", line 25, in getTableData
    f.write(data)
  File "C:\Python\Python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 12-15: character maps to <undefined>

When I print(data) lots of random symbols come out along with some text - this might be why, but how do I avoid this?

0 Answers0