UnicodeDecodeError:在python 2.7中

时间:2015-05-19 15:10:05

标签: python-2.7 encoding

我正在使用VirusTotal api,正是如下: https://www.virustotal.com/es/documentation/public-api/#scanning-files

这是我的scritp中我遇到问题的部分:

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)

对于某些文件没有任何错误并且运行正常,但是在尝试扫描某些文件时发生了下一个错误,例如此错误是针对jpg文件的:

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)

我应该指出我在windows下使用pycharm,这会导致编码错误吗?

知道怎么解决吗?我有堆栈,无法在网上找到任何解决方案。

0 个答案:

没有答案