问题
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()
The error I get is:
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.
回答1:
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.
来源:https://stackoverflow.com/questions/51660709/python-http-client-remotedisconnected