Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Agent addition #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tallesairan
Copy link

some security plugins are blocking requests without user-agent.
in this change I added a user-agent so it is possible to request

some security plugins are blocking requests without user-agent.
in this change I added a user-agent so it is possible to request
Copy link
Owner

@MickaelWalter MickaelWalter left a comment

Choose a reason for hiding this comment

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

Hi!

Thank you for your contribution. I was thinking about letting the User Agent choice but never ran into the use case. Would it be possible to add a new argument to the Argument Parser, then just pass the user choice to a RequestSession setter or directly as a RequestSession.__init__ argument? That would at least let the user choose which User Agent they want.

I foresee something like this:
--user-agent 1: allows to get a User Agent from a list of hardcoded common User Agents
--list-ua: allows to list the available hardcoded User Agents
--user-agent "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": allows to manually define any User Agent.

What do you think about this?

Comment on lines +107 to +109
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'
}
Copy link
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
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
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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants