From 4c29ed070a6c4e4b149d44691368b5aeb5d3c4e1 Mon Sep 17 00:00:00 2001 From: Brandon Koepke Date: Thu, 4 Dec 2014 21:30:13 +0000 Subject: [PATCH 1/2] Replaced urllib with requests api to fix cloudfare cookie error. --- gamesdb/api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gamesdb/api.py b/gamesdb/api.py index a8ddc4e..51082c1 100644 --- a/gamesdb/api.py +++ b/gamesdb/api.py @@ -1,4 +1,4 @@ -import urllib +import requests import xml.etree.ElementTree as ET from urlutils import urlencode_no_plus @@ -60,10 +60,10 @@ def make_call(api_url, query_args=None): # APIException, passing forward the pages contents (which generally gives some indication of the error. if query_args is not None: get_params = urlencode_no_plus.urlencode_no_plus(query_args) - response = urllib.urlopen(api_url+'%s' % get_params) + response = requests.get(api_url+'%s' % get_params) else: - response = urllib.urlopen(api_url) - page = response.read() + response = requests.get(api_url) + page = response.text # Make sure the XML Parser doesn't return a ParsError. If it does, it's probably and API Issue, so raise an # exception, printing the response from the API call. From ab3ea75c37e4b6e8071cee63ef6e40e8043ee5ab Mon Sep 17 00:00:00 2001 From: Brandon Koepke Date: Thu, 4 Dec 2014 21:52:35 +0000 Subject: [PATCH 2/2] Ignore ascii conversion errors --- gamesdb/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gamesdb/api.py b/gamesdb/api.py index 51082c1..72df639 100644 --- a/gamesdb/api.py +++ b/gamesdb/api.py @@ -63,7 +63,7 @@ def make_call(api_url, query_args=None): response = requests.get(api_url+'%s' % get_params) else: response = requests.get(api_url) - page = response.text + page = response.text.encode('ascii', 'ignore') # Make sure the XML Parser doesn't return a ParsError. If it does, it's probably and API Issue, so raise an # exception, printing the response from the API call.