Browse Source
Fix error handling of dblptex command
DBLP does not return a HTTP status code indicating that there is an
error but an error page instead. This is now checked by looking at the
content type. If something else than bibtex is returned, error out.
master
Maximilian Blochberger
4 years ago
No known key found for this signature in database
GPG Key ID: A2A8F3CC6591A5FA
1 changed files with
7 additions and
1 deletions
sok/management/commands/dblptex.py
@ -1,6 +1,6 @@
import requests
import requests
from django . core . management . base import BaseCommand , CommandParser
from django . core . management . base import BaseCommand , CommandError , Command Parser
import sok . management . commands . dblpimport as dblp
import sok . management . commands . dblpimport as dblp
@ -17,4 +17,10 @@ class Command(BaseCommand):
url = f ' https://dblp.uni-trier.de/rec/ { key } .bib?param=0 '
url = f ' https://dblp.uni-trier.de/rec/ { key } .bib?param=0 '
response = requests . get ( url )
response = requests . get ( url )
response . raise_for_status
response . raise_for_status
# The status does not necessarily indicate success, but returns an error
# page instead.
if ' application/x-bibtex ' not in response . headers [ ' Content-Type ' ] :
raise CommandError ( url )
self . stdout . write ( response . content . decode ( ) )
self . stdout . write ( response . content . decode ( ) )