-
Notifications
You must be signed in to change notification settings - Fork 19
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
Suppress the user-agent from newer versions of urllib3 #24
Conversation
I'm not sure what is causing the Python 3.5 version to fail, but the module-related error does not seem related to the changes but to the testing setup. This request may well fix #21. |
This pr could be a good temporarly fix for this issue until or if upstream pyrequest implement urlib3 skip_header function: psf/requests#5671 |
@filcole Would you kindly have a look at the pull request? Your module is being used by (at least) Home Assistant and these integrations break for a lot of users because of the newer |
'POST', | ||
url=BASE_URL + endpoint, | ||
data=params, | ||
headers={"User-Agent": ""} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we might want to leave a developers/comment/note around here explaining why we're forging the UserAgent
to empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my research, so long as it's not clearly urllib (or cURL - that took a while to debug) any useragent (or no useragent) seems to work. Setting it to "My PyCarwings Lib/2.whatever" also works, and might be considered more valid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But setting it to default User-agent that urllib3 forces does not work.
This has been tested here: home-assistant/core#43312 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I was saying that rather than forging it to empty and needing a note to explain why, it could instead be set to a human-readable value that isn't rejected by the carwings servers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is also something, it was promoted here: home-assistant/core#43312 (comment)
Problem is that no one has tested/mapped what User-Agent headers are accepted.
overall LGTM! ✔️ |
@@ -118,7 +118,12 @@ def _request(self, endpoint, params): | |||
else: | |||
params["custom_sessionid"] = "" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the change here adds headers
as a dictionary, and this conforms to the documentation
https://docs.python.org/3/library/urllib.request.html#urllib.request.Request
✔️
@filcole Could you take a look at this? |
It seems that pyrequest is sorting out the problem with urllib3 here: psf/requests#5671 If this proposed pr are introduced into pyrequest it will require a change with the current pr for pycarwings2
Need to be:
|
I think we should include a User-Agent in pycarwings2 since I think it's good practice. I don't know what the Nissan Leaf app sends, but I think MyLeaf is sending Not sending User-Agent works ✔ So it appears that when lowercase 'python' is part of the user agent string the Nissan servers return an error. I will use |
Thank you to all who contributed. I've tweaked the pull request and incorporated the changes via PR #25 |
Nice! Great work all. Once we get a |
Pycarwings2 2.10 contains this fix and is included in Home Assistant Core
2020.12.2.
…On Thu, 31 Dec 2020, 13:58 Fermulator, ***@***.***> wrote:
Nice! Great work all. Once we get a pycarwings2 release/version, please
notify, then we can have homeassistant pull in the changes
https://github.com/home-assistant/core/blob/dev/homeassistant/components/nissan_leaf/manifest.json#L5
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#24 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABOL7PUWKQ3DKRR45KHGSXLSXR7OZANCNFSM4UEYMYUQ>
.
|
FYI: Did not fix #21 sadly. |
Seit Nov 2020 braucht es wohl einen user-agent Heade4 in der Request (siehe filcole/pycarwings2#24). Ist der einzige Unterschied zur in OpenWB verwendeten Funktion. Sollte also auch für OpenWB das Problem lösen. Bitte in ein der nächsten Releases einfließen lassen.
Newer versions of urllib3, such as those being used by Home Assistant, automatically add a User-Agent header to the request. It seems, from trial and error, that sending over a
User-Agent
header breaks the API leading to responses as "INVALID PARAMS".This pull request adds an additional parameter in the
_request
body to suppress theUser-Agent
header from being automatically filled.