Skip to content

Commit

Permalink
Include User-Agent Header in Calls to ONCat API (#6)
Browse files Browse the repository at this point in the history
* Add user agent info as header to ONCat API calls.

* Actually pass request object to urllib...

* Use a more standard format agent string.
  • Loading branch information
PeterParker authored and peterfpeterson committed Nov 5, 2018
1 parent 19b08de commit b50efd6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scripts/finddata
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import os
import re
import sys
try:
from urllib import urlopen
from urllib2 import Request, urlopen
except ImportError:
from urllib.request import urlopen
from urllib.request import Request, urlopen
from finddata import __version__

BASE_URL = 'https://oncat.ornl.gov/'
Expand Down Expand Up @@ -56,7 +56,9 @@ def procNumbers(numbers):

def getJson(endpoint):
url = BASE_URL + endpoint
handle = urlopen(url)
req = Request(url)
req.add_header('User-Agent', 'Finddata/' + __version__)
handle = urlopen(req)
if handle.getcode() != 200:
raise RuntimeError('{} returned code={}'.format(url, handle.getcode()))
doc = handle.read().decode()
Expand Down

0 comments on commit b50efd6

Please sign in to comment.