From b50efd6f82f9948a2f7da6f52a54c2c10af97019 Mon Sep 17 00:00:00 2001 From: PeterParker Date: Mon, 5 Nov 2018 13:48:46 -0500 Subject: [PATCH] Include User-Agent Header in Calls to ONCat API (#6) * Add user agent info as header to ONCat API calls. * Actually pass request object to urllib... * Use a more standard format agent string. --- scripts/finddata | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/finddata b/scripts/finddata index 89ea50f..1077b86 100755 --- a/scripts/finddata +++ b/scripts/finddata @@ -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/' @@ -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()