Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/requestsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ def do_request(self, method, url, data=None):
Helper class to regroup requests and handle exceptions at the same
location
"""
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36'
}
Comment on lines +107 to +109

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to avoid hardcoded User Agent and rather use a flag on the command line? (e.g. --ua or --user-agent flag). It would need to add the argument in the ArgumentParser, and add a setter or a parameter to RequestSession.init. Shouldn't be too hard. Maybe it would be also useful to add a little set of common User Agents in the code and let the user choose in it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm working on the changes, i have python as an adventure since i always programmed PHP haha

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take your time.
I haven't updated it for 9 months anyway :D

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MickaelWalter I hard-coded a fix onto my copy a while back, but I agree that a multi-faceted approach (with the three flags you mentioned) works best. Also wanted to say this tool has been incredibly useful in my work. Thanks for building it.

response = None
try:
if method == "post":
response = self.s.post(url, data)
response = self.s.post(url, data, headers=headers)
else:
response = self.s.get(url)
response = self.s.get(url, data=None, header=headers)
except requests.ConnectionError as e:
if "Errno -5" in str(e) or "Errno -2" in str(e)\
or "Errno -3" in str(e):
Expand Down Expand Up @@ -179,4 +182,4 @@ def set_creds(self, credentials):
self.s.auth = credentials

def get_creds(self):
return self.s.auth
return self.s.auth