1

I want to fetch Bibtex citation from doi in Python. So the way I achieved it is by using this function:

   def BibtexFromDoi(doi):
       url =  "http://dx.doi.org/" + doi
       headers = {"accept": "application/x-bibtex"}
       r = requests.get(url, headers=headers)
       return r.text

The problem with that, is that it takes so long to run this code, it takes from 10 to 15 minutes to get a response. I was wondering on what can be done to enhance the code and make it run faster In addition, I tried using Curl on the command line and it turns out to be faster with Curl, it only takes 1 to 2 seconds. I would like to achieve the same spead but on python.

celia
  • 33
  • 10
  • 1
    Works fine for me. Have you tried different DOIs? Can you post which one(s) you've tested? – Antimon Dec 16 '21 at 00:28
  • Yes, I have tried different DOIs too, none of them worked properly. I suspect it's because of the URL, after trying with a different one `url = "http://api.crossref.org/works/" + doi +"/transform/application/x-bibtex"` it seem to work faster, but I still don't understand why. – celia Dec 16 '21 at 08:35
  • That's odd. What python version are you running? – Antimon Dec 16 '21 at 19:56
  • I am using Python 3.9.7 – celia Dec 16 '21 at 22:14
  • Does this also happen when you try a normal request with any other website? Maybe it's got something to do with the header request... – Antimon Dec 17 '21 at 18:31
  • No, it doesn't happen with other websites – celia Dec 18 '21 at 17:01

0 Answers0