【问题标题】:How to solve "[Winerror]:10054 An existing connection was forcibly closed by the remote host"?如何解决“[Winerror]:10054 现有连接被远程主机强行关闭”?
【发布时间】:2021-06-30 04:15:30
【问题描述】:

我正在尝试使用 VirusTotal API 获取 json 响应。为了获取结果作为响应,我创建了一个 python 脚本,如下所示:然后错误显示如下:[Winerror]:10054 现有连接被远程主机强行关闭

import requests

url = "https://www.virustotal.com/vtapi/v2/file/scan"

api_key = "MyApiKey"

params = {"apikey": api_key}

files = {"file": ("app.exe", open("C:/Users/Administrator/Desktop/malware detection/app.exe", "rb")} 
try:
    response = requests.post(url, files=files, params=params)
    print(response.json())

except Exception as e:
    print(e)

【问题讨论】:

    标签: python malware malware-detection


    【解决方案1】:

    要提供更多信息,请尝试以下操作:

    import requests
    
    url = "https://www.virustotal.com/vtapi/v2/file/scan"
    
    api_key = "MyApiKey"
    
    params = {"apikey": api_key}
    
    files = {"file": ("app.exe", open("C:/Users/Administrator/Desktop/malware detection/app.exe", "rb"))} 
    try:
        response = requests.post(url, files=files, params=params)
        print(response.json())
    
    except Exception as e:
        print(e)
    

    并发布您从更新后的代码收到的错误响应。

    【讨论】:

    • 请找截图
    • 我不确定这是否与它有关,但您在原始帖子中缺少一个结束括号,我在回复中不知何故忽略了它。尝试我的答案的更新版本。抱歉,我无法在上传答案之前进行测试。希望只是愚蠢的错字破坏了您的代码。奇怪的是您的 IDE 没有捕捉到它?
    • 感谢您的回复。经过一个小时的搜索,我发现问题实际上不在代码中。问题出在我尝试扫描的应用程序中。我尝试了另一个应用程序来获取扫描报告,并且它适用于相同的代码。
    • 很高兴听到您解决了这个问题。请考虑发布或链接到解决未来搜索者问题的功能代码。我也很感兴趣,因为您发布的示例直接取自 VirusTotal.com 文档。是否像迁移到 V3 API 一样简单(我想这意味着 v2 已被弃用?)
    猜你喜欢
    • 2020-04-20
    • 2018-01-02
    • 2016-10-20
    • 2015-02-28
    • 2015-05-24
    • 2021-05-25
    • 1970-01-01
    • 2020-10-09
    • 2021-08-02
    相关资源
    最近更新 更多