pylast icon indicating copy to clipboard operation
pylast copied to clipboard

Restore proxy support

Open itisFarzin opened this issue 6 months ago • 10 comments

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:

  • proxies changed to proxy
  • class _Network and its subclasses now has the proxy argument

itisFarzin avatar May 30 '25 10:05 itisFarzin

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

hugovk avatar May 31 '25 05:05 hugovk

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

Based on the changelog, that argument got added in 0.26.0. I'll update the dependencies.

itisFarzin avatar May 31 '25 09:05 itisFarzin

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

itisFarzin avatar May 31 '25 09:05 itisFarzin

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.

Good idea, let's do this.

hugovk avatar Jun 09 '25 09:06 hugovk

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")}

itisFarzin avatar Jun 12 '25 13:06 itisFarzin

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)

hugovk avatar Jun 12 '25 14:06 hugovk

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?

hugovk avatar Jun 13 '25 09:06 hugovk

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.

itisFarzin avatar Jun 13 '25 13:06 itisFarzin

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?

hugovk avatar Jun 13 '25 20:06 hugovk

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.

itisFarzin avatar Jun 17 '25 10:06 itisFarzin

@hugovk, when this will be merged?

itisFarzin avatar Sep 24 '25 06:09 itisFarzin

Thanks for the ping, I'm travelling right now but will aim to get this merged and released by the end of next week.

hugovk avatar Sep 24 '25 07:09 hugovk

Thanks — safe travels.

itisFarzin avatar Sep 29 '25 04:09 itisFarzin

This is now released in pylast 6.0.0. Thanks for the fix!

hugovk avatar Sep 29 '25 12:09 hugovk