Question: Biopython TimeExceptionError how to handle?
0
gravatar for Xylanaser
2.6 years ago by
Xylanaser60
Poland - Warsaw - SGGW/WULS
Xylanaser60 wrote:

Hey how can i handle TimeExceptionError? Im downloading abstracts and sometimes it occurs. Cheers,X

edit: to be clear sometimes after 100 abstracts, sometimes after 10000

Traceback (most recent call last):

  File "<ipython-input-17-d84c4160e0e2>", line 1, in <module>
    runfile('C:/Users/m/Dropbox/getabsA.py', wdir='C:/Users/m/scripts')

  File "C:\Users\m\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
    execfile(filename, namespace)

  File "C:\Users\m\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/m/Dropbox/getabsA.py", line 65, in <module>
    rettype ='medline', retmode = 'gb')

  File "C:\Users\m\Anaconda3\lib\site-packages\Bio\Entrez\__init__.py", line 180, in efetch
    return _open(cgi, variables, post=post)

  File "C:\Users\m\Anaconda3\lib\site-packages\Bio\Entrez\__init__.py", line 527, in _open
    handle = _urlopen(cgi)

  File "C:\Users\m\Anaconda3\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)

  File "C:\Users\m\Anaconda3\lib\urllib\request.py", line 526, in open
    response = self._open(req, data)

  File "C:\Users\m\Anaconda3\lib\urllib\request.py", line 544, in _open
    '_open', req)

  File "C:\Users\m\Anaconda3\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)

  File "C:\Users\m\Anaconda3\lib\urllib\request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)

  File "C:\Users\m\Anaconda3\lib\urllib\request.py", line 1321, in do_open
    r = h.getresponse()

  File "C:\Users\m\Anaconda3\lib\http\client.py", line 1331, in getresponse
    response.begin()

  File "C:\Users\m\Anaconda3\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()

  File "C:\Users\m\Anaconda3\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")

  File "C:\Users\m\Anaconda3\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)

  File "C:\Users\m\Anaconda3\lib\ssl.py", line 1002, in recv_into
    return self.read(nbytes, buffer)

  File "C:\Users\m\Anaconda3\lib\ssl.py", line 865, in read
    return self._sslobj.read(len, buffer)

  File "C:\Users\m\Anaconda3\lib\ssl.py", line 625, in read
    v = self._sslobj.read(len, buffer)




TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

my code here:

abstracts_holder = []
counterAB = 0
my_list = open('my_list.txt', 'r')

for ID in my_list:

    handle = Entrez.efetch(db="pubmed", id=ID,
                           rettype ='medline', retmode = 'gb')
    medRecords=Medline.parse(handle)
    for rec in medRecords:
        counterAB+=1
        print('counterAB:',counterAB)

        if rec.get('AB') != None :
            abstracts_holder.append(rec.get('AB'))
            abstracts_holder.append('\n')
        else:
            continue


    handle.close()
ADD COMMENTlink modified 2.6 years ago • written 2.6 years ago by Xylanaser60

It might be useful to:

  • Show the code you are using
  • Show the exact Exception you get

Without that information, you are making this quite hard for us to guess.

Interesting guidelines for posting can be found in the following posts:

ADD REPLYlink modified 2.6 years ago • written 2.6 years ago by WouterDeCoster43k
1

Do you just want to catch the error so that it doesn't go un-handled or do you want to remedy the problem of not retrieving abstracts?

ADD REPLYlink written 2.6 years ago by Joe16k

I add some things , i want remedy the problem of not retrieving abstracts

ADD REPLYlink modified 2.6 years ago • written 2.6 years ago by Xylanaser60
2

I would suggest adding a time.sleep(5) in the loop, to avoid hammering the server with too many requests.

ADD REPLYlink written 2.6 years ago by WouterDeCoster43k

Would be my guess too. The server is probably kicking you off to avoid traffic overload.

If its not that, then somewhere along the pipeline you have an unstable network connection I would suppose, and I doubt there's a massive amount you could do about it if thats the case.

ADD REPLYlink written 2.6 years ago by Joe16k

Thanks for advice, i do the program that download sequences and give time.sleep(1) and its work well. Forgot about that :)

ADD REPLYlink written 2.6 years ago by Xylanaser60
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 845 users visited in the last hour