Skip to content

Commit

Permalink
Fixed start issue
Browse files Browse the repository at this point in the history
-Added browser headers to the API POST requests, which prevent the request from being invalid
  • Loading branch information
EternalTrail authored Apr 28, 2020
1 parent fab991f commit a2fdb11
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions PageTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
import ssl
import json

browserHeader = {'User-Agent': 'Mozilla/5.0 (Macintosh;Intel Mac OS X 10_9_3)'+\
' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'}

class PageTools():

def downloadPage(self, url, timeout = 5, attempts = 5):

# Fake browser headers
ssl._create_default_https_context = ssl._create_unverified_context
urlReq = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0 (Macintosh;Intel Mac OS X 10_9_3)'+\
' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'})
urlReq = urllib.request.Request(url, headers=browserHeader)

# Open url, read the response and return it, attempty
for i in range(attempts):
Expand All @@ -35,7 +36,7 @@ def getJsonFromUrl(self, url):
def getJsonFromPost(self, url, jsonPayload):

# Do a POST request to get the JSON file back
response = requests.post(url, json = json.loads(jsonPayload))
response = requests.post(url, json = json.loads(jsonPayload), headers=browserHeader)
jsonFile = json.loads(response.text)
return jsonFile

Expand Down

0 comments on commit a2fdb11

Please sign in to comment.