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

Add custom user-agent headers #37

Merged
merged 1 commit into from
Oct 28, 2022

Conversation

muppet3000
Copy link
Contributor

Fix for #36

NOTE - The 'User-Agent' header can actually be set to anything, including an empty string. However, I wanted to make it look as close as possible to an actual Android device so it's not easy to filter out on the growatt server side i.e. reducing the likelihood of getting blocked again in the future.

I'm happy to take an alternative solution, but this is the best that I could come up with.

Once merged & released this will also need to be updated on the HA integration to resolve this problem: home-assistant/core#80950

@indykoning
Copy link
Owner

I agree, we want the requests to match closely to prevent any problems from happening. So this looks good to me 🚀
I'm guessing we can't pass the headers to the session constructor right?
I'll try and get a release sorted this evening 👍

@muppet3000
Copy link
Contributor Author

Hero!

You can't pass it straight to the session constructor from what I can tell, even their documentation says to do it this way: https://requests.readthedocs.io/en/latest/user/advanced/
Looking at the source code: https://requests.readthedocs.io/en/latest/_modules/requests/sessions/#Session there is a function call to default_headers which wouldn't allow us to override it, so this is the correct option IMO.

It would be awesome if you could turn around a release this evening with just this fix in it because then I can submit the PR for HA straight afterwards and everything will be in a good place again.

Thanks for the quick response.

@indykoning indykoning changed the title Adding headers to session to ensure we aren't rejected by the growatt servers (#36) Add custom user-agent headers Oct 28, 2022
@indykoning indykoning merged commit 5188178 into indykoning:master Oct 28, 2022
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.

2 participants