Python http.client.RemoteDisconnected [英] Python http.client.RemoteDisconnected

查看:40
本文介绍了Python http.client.RemoteDisconnected的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用 python 通过网络服务运行多个 id,我收到http.client.RemoteDisconnected: Remote end closed connection without response"错误.我不想尝试/捕获这个错误,我想调查为什么我得到这个响应.我已经能够得到 400 和 500 级错误

Trying to run several ids through a webservice using python and I am getting the 'http.client.RemoteDisconnected: Remote end closed connection without response' error. I don't want to try/catch this error, I want to investigate why I am getting this response. I have been able to get 400 and 500 level errors

raise HTTPError(req.full_url, code, msg, hdrs, fp)
    urllib.error.HTTPError: HTTP Error 413:

使用我在下面包含的方法,并且我理解了这些错误(所以我不相信错误与我的编码方式有关,但谁知道)

using the method I am including below, and I understood those errors (so I don't believe the error is related to how I have coded this but who knows)

import pandas as pd
from urllib.parse import urlencode
import urllib.request
contact = ""
url = 'https://www.uniprot.org/uploadlists/'
mouse_ten_tissues = pd.read_csv('Z:\\\mouse_data\\refex\\RefEx_expression_RNAseq10_mouse_PRJNA30467.tsv',
                            delimiter='\t', encoding='utf-8')
mouse_ten_refseq = mouse_ten_tissues['NCBI_RefSeqID'].to_string()
query_mouse_human_refseq_id_params = {
    'from': 'REFSEQ_NT_ID',
    'to': 'GENENAME',
    'format': 'tab',
    'query': mouse_ten_refseq
}

query_mouse_human_refseq_id_data = urlencode(query_mouse_human_refseq_id_params).encode("utf-8")
query_mouse_human_refseq_id_request = urllib.request.Request(url, query_mouse_human_refseq_id_data)
query_mouse_human_refseq_id_request.add_header('User-Agent', 'Python %s' % contact)

query_mouse_human_refseq_id_response = urllib.request.urlopen(query_mouse_human_refseq_id_request)

with query_mouse_human_refseq_id_response as f:
    query_mouse_human_refseq_id_resp = f.read()

我得到的错误是:

Traceback (most recent call last):
  File "C:/Users/me/read_data.py", line 35, in <module>
    query_mouse_human_refseq_id_response = urllib.request.urlopen(query_mouse_human_refseq_id_request)
  File "C:\Users\me\Python\Python37-32\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\me\Python\Python37-32\lib\urllib\request.py", line 525, in open
    response = self._open(req, data)
  File "C:\Users\me\Python\Python37-32\lib\urllib\request.py", line 543, in _open
    '_open', req)
  File "C:\Users\me\Python\Python37-32\lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
  File "C:\Users\me\Python\Python37-32\lib\urllib\request.py", line 1360, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "C:\Users\me\Python\Python37-32\lib\urllib\request.py", line 1320, in do_open
    r = h.getresponse()
  File "C:\Users\me\Python\Python37-32\lib\http\client.py", line 1321, in getresponse
    response.begin()
  File "C:\Users\me\Python\Python37-32\lib\http\client.py", line 296, in begin
    version, status, reason = self._read_status()
  File "C:\Users\me\Python\Python37-32\lib\http\client.py", line 265, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

我一直在阅读文档,但我不知道如何获得更具描述性的错误或如何调试.我应该假设这是超时问题还是我提交的列表太大?通过我对这个问题的谷歌探索,我没有找到太多的解释方式.

I've been reading through the documentation but I don't know how to get a more descriptive error or how to debug. Should I assume that it's a time out issue or that the list I am submitting is too large? I haven't been able to find much in the way of explanation through my google exploration of the issue.

推荐答案

最佳答案是评论.由于我的互联网速度/不稳定的互联网,我很可能遇到问题,因为有时收到响应,有时没有响应.

The best answer was a comment. Most likely I am hitting issues due to my internet speed/spotty internet, as sometime response is received and sometimes no response.

这篇关于Python http.client.RemoteDisconnected的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆