Restore proxy support
The deprecated proxies argument used for proxy support was removed in httpx 0.28.0.
This commit replaces the deprecated proxies argument with proxy to restore functionality.
The proxy argument has also been added to the _Network and it's subclasses, for easier set up.
Fixes #486
Changes proposed in this pull request:
proxieschanged toproxy- class
_Networkand its subclasses now has theproxyargument
Thanks for the PR.
In which version of HTTPX was the proxy argument added?
We should require at least that version at
https://github.com/pylast/pylast/blob/f4800917c905c9503eebd04e3b74f9fdfafe618c/pyproject.toml#L40-L42
Thanks for the PR.
In which version of HTTPX was the
proxyargument added?We should require at least that version at
https://github.com/pylast/pylast/blob/f4800917c905c9503eebd04e3b74f9fdfafe618c/pyproject.toml#L40-L42
Based on the changelog, that argument got added in 0.26.0. I'll update the dependencies.
By the way, we can simplify the instantiation of the HTTPX client.
is_proxy_enabled checks if the proxy is None or not, and based on that, client gets initialized. We can pass the None value to the proxy argument and removing the unnecessary check.
https://github.com/pylast/pylast/blob/08d791793766bc1ac22cde72db914ed15bdb1a06/src/pylast/init.py#L915-L929
By the way, we can simplify the instantiation of the HTTPX client.
is_proxy_enabledchecks if the proxy is None or not, and based on that, client gets initialized. We can pass the None value to theproxyargument and removing the unnecessary check.
Good idea, let's do this.
https://github.com/pylast/pylast/pull/487/commits/300320ff1f075c7f93cd665e51964e820acef17c#diff-bdfc4afd1c1f888b812a0b0e0ff710ed101c69370a4634b2430c2d1d3ef97275R199-R210
With this change, the proxy types below will work:
"socks5://192.168.1.71:10808"
{"https://": "socks5://192.168.1.71:10808"} # (For not breaking old codes)
{"https://": httpx.HTTPTransport(proxy="socks5://192.168.1.71:10808")}
Thanks! Don't worry about most of the CI failures, that's because of https://github.com/pylast/pylast/issues/171.
But please could you check the lint/mypy one? You can test it locally with tox -e mypy.
src/pylast/__init__.py:428: error: Incompatible types in assignment (expression
has type "str | dict[Any, Any]", variable has type
"dict[str, HTTPTransport] | None") [assignment]
self.proxy = proxy
^~~~~
Found 1 error in 1 file (checked 2 source files)
Testing locally, some tests also need updating:
=============================================================== short test summary info ===============================================================
FAILED tests/test_network.py::TestPyLastNetwork::test_proxy - AssertionError: assert {'https://': 'http://example.com:1234'} == 'http://example.com:1234'
FAILED tests/test_network.py::TestPyLastNetwork::test_artist_search - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_country_top_artists - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_country_network_top_tracks - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_track_search_images - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_network_get_top_tags_with_limit - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_artist_mbid - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_country_top_tracks - pylast.PyLastError
FAILED tests/test_network.py::TestPyLastNetwork::test_network_get_top_artists_with_limit - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_album_search_images - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_geo_get_top_tracks - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_enable_rate_limiting - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_caching - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_track_data - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_disable_rate_limiting - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_tag_top_tracks - pylast.PyLastError
FAILED tests/test_network.py::TestPyLastNetwork::test_track_mbid - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_geo_get_top_artists - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_track_search - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
FAILED tests/test_network.py::TestPyLastNetwork::test_network_get_top_tracks_with_limit - pylast.NetworkError: NetworkError: 'str' object has no attribute 'handle_request'
=========================================== 20 failed, 111 passed, 9 skipped, 1 xfailed in 96.49s (0:01:36) ===========================================
Please can you look into it?
Please can you look into it?
I'd love to, but due to recent events in my country (Iran), our network has gotten even worse, and I can't run the tests locally.
I understand. I had a look, and only one change was needed for one test, so I've pushed it to this PR.
The thing to consider if this is a breaking change, as the value in network.proxy has changed. Maybe it's okay to change and put this out as a new major version?
I don't think this is a breaking change. ~The old way of using a proxy is still working and if someone used the multiple proxy one (which I don't think someone actually did, since this library only do https requests), that still works.~
EDIT: I think this can be counted as a breaking change.
@hugovk, when this will be merged?
Thanks for the ping, I'm travelling right now but will aim to get this merged and released by the end of next week.
Thanks — safe travels.
This is now released in pylast 6.0.0. Thanks for the fix!