Skip to content

Commit

Permalink
Merge pull request #57 from LLNL/github-header-fix
Browse files Browse the repository at this point in the history
Fix for GitHub API missing Status header.
  • Loading branch information
IanLee1521 authored Feb 6, 2021
2 parents 3cc5c7e + 2faf074 commit 559e5ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python:
install:
- pip install flake8 bandit black
- pip install .
- npm install -g markdownlint-cli
- npm install -g markdownlint-cli@0.23.2

script:
- make test
Expand Down
17 changes: 10 additions & 7 deletions scraper/github/queryManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, apiToken=None, maxRetry=10):
print("FAILED.")
raise ValueError(
"GitHub API token is not valid.\n%s %s"
% (basicCheck["headDict"]["Status"], basicCheck["result"])
% (basicCheck["statusTxt"], basicCheck["result"])
)
else:
print("Token validated.")
Expand Down Expand Up @@ -252,7 +252,7 @@ def queryGitHub(
headers=headers,
)
_vPrint((verbosity >= 0), "Checking response...")
_vPrint((verbosity >= 0), "HTTP/1.1 " + response["headDict"]["Status"])
_vPrint((verbosity >= 0), "HTTP STATUS %s" % (response["statusTxt"]))
statusNum = response["statusNum"]

# Decrement page count before error checks to properly reflect any repeated queries
Expand Down Expand Up @@ -293,7 +293,7 @@ def queryGitHub(
"Query attempted but failed %d times.\n%s\n%s"
% (
self.maxRetry,
response["headDict"]["Status"],
response["statusTxt"],
response["result"],
)
)
Expand Down Expand Up @@ -322,7 +322,7 @@ def queryGitHub(
"Query attempted but failed %d times.\n%s\n%s"
% (
self.maxRetry,
response["headDict"]["Status"],
response["statusTxt"],
response["result"],
)
)
Expand All @@ -348,7 +348,7 @@ def queryGitHub(
if statusNum >= 400 or statusNum == 204:
raise RuntimeError(
"Request got an Error response.\n%s\n%s"
% (response["headDict"]["Status"], response["result"])
% (response["statusTxt"], response["result"])
)

_vPrint((verbosity >= 0), "Data received!")
Expand All @@ -361,7 +361,7 @@ def queryGitHub(
"Query attempted but failed %d times.\n%s\n%s"
% (
self.maxRetry,
response["headDict"]["Status"],
response["statusTxt"],
response["result"],
)
)
Expand Down Expand Up @@ -469,6 +469,7 @@ def _submitQuery(
Returns:
{
'statusNum' (int): The HTTP status code.
'statusTxt' (str): The HTTP status message.
'headDict' (Dict[str]): The response headers.
'linkDict' (Dict[int]): Link based pagination data.
'result' (str): The body of the response.
Expand Down Expand Up @@ -501,7 +502,8 @@ def _submitQuery(
)
result = fullResponse.text
headDict = fullResponse.headers
statusNum = int(headDict["Status"].split()[0])
statusNum = int(fullResponse.status_code)
statusTxt = "%d %s" % (statusNum, fullResponse.reason)

# Parse any Link headers even further
linkDict = None
Expand All @@ -515,6 +517,7 @@ def _submitQuery(

return {
"statusNum": statusNum,
"statusTxt": statusTxt,
"headDict": headDict,
"linkDict": linkDict,
"result": result,
Expand Down

0 comments on commit 559e5ba

Please sign in to comment.