2

I'm run my code to extract required data from RNA central database based RNAcentral accession number.

Sometimes in the middle, the program stops and start showing this error:

Error Obtained


  File "C:\Users\soura\Desktop\Thesis\Saurav Data\Data_Extraction_RNA_Central.py", line 53, in <module>
    data = page.json()['results']

  File "D:\programs\anaconda3\lib\site-packages\requests\models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)

  File "D:\programs\anaconda3\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)

  File "D:\programs\anaconda3\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())

  File "D:\programs\anaconda3\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting value

This is the part of my code where I'm having an error

import requests
import time

ids = ['URS0000D57BCE', 'URS0000D57BCE', 'URS0000EEF870', 'URS00009C33DE']

for id in range(len(ids)):
    # Accessing the database cross-reference url with exception handling and extracting info
    page = ''
    while page == '':

        try:
            page = requests.get('http://rnacentral.org/api/v1/rna/{}/xrefs.json'.format(ids[id]))
            break  
        except:
            print('Connection refused by the server at id {} and position {}'.format(ids[id], ids.index(ids[id])))
            print('Lets me sleep for 5 seconds')
            time.sleep(5)
            continue
        
    # Extracting json content from above url
    data = page.json()['results']

Later I modified my code like this but still, I'm getting the same error:

I Changed page = '' to page = None I thought since the error is for the None value of the page. I wrote a while loop in such a way until there is the None value of page, the code will re-run again and again.

import requests
import time

ids = ['URS0000D57BCE', 'URS0000D57BCE', 'URS0000EEF870', 'URS00009C33DE']

for id in range(len(ids)):
    # Accessing the database cross-reference url with exception handling and extracting info
    page = None
    while page == None:

        try:
            page = requests.get('http://rnacentral.org/api/v1/rna/{}/xrefs.json'.format(ids[id]))
            break  
        except:
            print('Connection refused by the server at id {} and position {}'.format(ids[id], ids.index(ids[id])))
            print('Lets me sleep for 5 seconds')
            time.sleep(5)
            continue
        
    # Extracting json content from above url
    data = page.json()['results']

Now, I'm getting this error:

Traceback (most recent call last):
  File "Data_Extraction_RNA_Central.py", line 61, in <module>
    data = page.json()['results']
  File "C:\Users\soura\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\soura\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\soura\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\soura\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Please if anyone can help, it will be a great help for me. :-)

0 Answers0