Forces utf8 when no encoding in header for DOI request.
The default behavior from the requests library is to use the guess from chardet which is not always reliable while doi.org seems to always return utf8 encoded data. It's unlikely that this changes without also updating the header.
This commit is contained in:
parent
cf596206b0
commit
7b19a9dcdd
@ -3,15 +3,19 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def doi2bibtex(doi):
|
||||
"""Return a bibtex string of metadata from a DOI"""
|
||||
|
||||
url = 'http://dx.doi.org/{}'.format(doi)
|
||||
headers = {'accept': 'application/x-bibtex'}
|
||||
r = requests.get(url, headers=headers)
|
||||
if r.encoding is None:
|
||||
r.encoding = 'utf8' # Do not rely on guessing from request
|
||||
|
||||
return r.text
|
||||
|
||||
|
||||
def isbn2bibtex(isbn):
|
||||
"""Return a bibtex string of metadata from a DOI"""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user