【问题标题】:Generate JSON reports for values stored in a list using python使用 python 为存储在列表中的值生成 JSON 报告
【发布时间】:2019-04-24 18:32:24
【问题描述】:

我正在使用 VirusTotal API 发送不同文件的请求(以哈希码的形式)并检查它们是否包含任何病毒。所以,我有一个名为“resources”的列表,其中包含不同文件(大约 4000 个文件)的哈希值。

我仅针对“资源”中的前 10 个值尝试了以下代码:

    for row in range(1,11):
        url = 'https://www.virustotal.com/vtapi/v2/file/report'
        params = {'apikey': apikey, 'resource':resources[row]}
        response = requests.get(url, params=params)
        response.json()

但它在执行时给了我以下错误:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

我不明白这个错误是什么意思,我该如何纠正它。请帮忙。

【问题讨论】:

  • 通常您必须为 JSON 输入内容类型标头或输入不同的 url 以获取 JSON。您确定要请求 JSON 吗?
  • @DanielButler 我必须将它放在内容类型标题中。基本上,我想遍历列表“资源”来为每个文件的哈希码生成结果。
  • 这个错误让我相信你没有从你的请求中得到 json。你能证明你是吗?
  • @DanielButler 是的,你是对的。我没有从我的请求中得到 json。

标签: json python-3.x


【解决方案1】:

我建议你使用urllib 模块。此代码适用于Python27。我猜它已经在Python3x 中进行了一些重构。请参阅https://docs.python.org/2/library/urllib.html 了解更多信息。

这是代码的更新版本 (Python27)。您能否告诉我们这是否可行?

import urllib   
for row in range(1,11):
     url = 'https://www.virustotal.com/vtapi/v2/file/report'
     params = {'apikey': apikey, 'resource':resources[row]}
     urlnew = urllib.quote_plus(url) 
     paramsNew = urllib.quote_plus(params) 
     response = requests.get(urlnew, params=paramsNew)
     response.json()

【讨论】:

  • 它给出一个错误:TypeError: quote_from_bytes() expected bytes
猜你喜欢
  • 2021-10-27
  • 2013-12-11
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-31
相关资源
最近更新 更多