From 2997d7d79378d3a688258f50761a26e2fb3490af Mon Sep 17 00:00:00 2001 From: Taylor Dawson Date: Thu, 21 Dec 2017 13:03:04 -0800 Subject: [PATCH 1/2] Revised the connect method When there was an error with the request, the connect method was returning the string "Connection refused". This would cause errors in the subclasses. So I have it printing the string and then exiting. I think in the future exceptions should be used. --- etherscan/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/etherscan/client.py b/etherscan/client.py index 08928ce..9cf0416 100644 --- a/etherscan/client.py +++ b/etherscan/client.py @@ -82,7 +82,9 @@ def connect(self): try: req = self.http.get(self.url) except requests.exceptions.ConnectionError: - return "Connection refused" + print("Connection refused") + exit() + if req.status_code == 200: # Check for empty response if req.text: From b158c2d65631085cc53337051a615aedee8bb128 Mon Sep 17 00:00:00 2001 From: Taylor Dawson Date: Thu, 21 Dec 2017 13:25:55 -0800 Subject: [PATCH 2/2] Fixed issue #14: - Checks that the status code is 1. If it's not then the program exits and returns the message field to the user. Incidentals: - I was using `json.loads()` to turn the respone text into json. However, the request object has a method which returns the json from the response. Thus, I have switched to using the `.json()` method. --- etherscan/client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/etherscan/client.py b/etherscan/client.py index 9cf0416..af06eaf 100644 --- a/etherscan/client.py +++ b/etherscan/client.py @@ -1,5 +1,4 @@ import requests -import json import collections # Assume user puts his API key in the api_key.json file under variable name "key" @@ -88,7 +87,11 @@ def connect(self): if req.status_code == 200: # Check for empty response if req.text: - return json.loads(req.text) + if req.json()['status'] == '1': + return req.json() + else: + print(req.json()['message']) + exit() else: print("Invalid Request") exit()