小编eur*_*lis的帖子

Python请求获取('连接中止.',BadStatusLine("''",))错误

def download_torrent(url):
    fname = os.getcwd() + '/' + url.split('title=')[-1] + '.torrent'
    try:
        schema = ('http:')
        r = requests.get(schema + url, stream=True)
        with open(fname, 'wb') as f:
            for chunk in r.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)
                    f.flush()
    except requests.exceptions.RequestException as e:
        print('\n' + OutColors.LR + str(e))
        sys.exit(1)

    return fname
Run Code Online (Sandbox Code Playgroud)

在那段代码中,当我运行完整的脚本时,我收到一个错误.当我去实际下载洪流时,我得到:

('Connection aborted.', BadStatusLine("''",))
Run Code Online (Sandbox Code Playgroud)

我只发布了我认为与上述相关的代码块.整个脚本如下.这是来自pantuts,但我认为它不再维持,我试图让它运行python3.根据我的研究,错误可能意味着我使用的是http而不是https,但我已经尝试了两种方法.

原始剧本

python python-3.x python-requests

25
推荐指数
1
解决办法
4万
查看次数

标签 统计

python ×1

python-3.x ×1

python-requests ×1