UnicodeDecodeError: in python 2.7

坚强是说给别人听的谎言 提交于 2019-12-24 15:08:18

问题


I am working with the VirusTotal api, exactly with this: https://www.virustotal.com/es/documentation/public-api/#scanning-files

This is the part of my scritp where im having problems:

def scanAFile(fileToScan):
    host = "www.virustotal.com"
    selector = "https://www.virustotal.com/vtapi/v2/file/scan"
    fields = [("apikey", myPublicKey)]
    file_to_send = open(fileToScan, "rb").read()
    files = [("file", fileToScan, file_to_send)]
    json = postfile.post_multipart(host, selector, fields, files)

    return simplejson.loads(json)

With some files there is not any error and it runs fine, but the next error is occurring when trying to scan some files, for example this error is for a jpg file:

Traceback (most recent call last):
  File "F:/devPy/myProjects/script_vt.py", line 138, in <module>
    scanMyFile()
  File "F:/devPy/myProjects/script_vt.py", line 75, in scanQueue
    jsonScan = scanAFile(fileToScan)
  File "F:/devPy/myProjects/script_vt.py", line 37, in scanAFile
    json = postfile.post_multipart(host, selector, fields, files)
  File "F:\devPy\myProjects\script_vt.py", line 10, in post_multipart
    content_type, body = encode_multipart_formdata(fields, files)
  File "F:\devPy\myProjects\script_vt.py", line 42, in encode_multipart_formdata
    body = CRLF.join(L)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

I should indicate I work with pycharm under windows, could this cause the encoding error?

Any idea how to solve it? I got stack and couldnt find any solution on the net.

来源:https://stackoverflow.com/questions/30329477/unicodedecodeerror-in-python-2-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!