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

Incorrect URL created when qBittorrent is behind a reverse proxy causing 404 error #37

Closed
zachoooo opened this issue Dec 6, 2020 · 5 comments

Comments

@zachoooo
Copy link

zachoooo commented Dec 6, 2020

I have my qBittorrent instance on a docker network along with a reverse proxy and the Web UI is available at http://[HOST]/qBittorrent/. The API is available and works correctly, when using curl or my browser. qbittorrent-api seems to ignore the base url and so I've been getting 404s when trying to use the API. Here is the example code:

qbt_client = qbittorrentapi.Client(host='http://[HOST]/qBittorrent/', username='[USERNAME]', password='[PASSWORD]')
@rmartin16
Copy link
Owner

can you please provide one of the working curl statements?

it looks like you're prefixing the Web API paths with qBittorrent....presumably the reverse proxy is then trimming the prefix to the qBittorrent instance. if that's the case, then yes...that is not supported....right now anyway. only the "host" portion (and a port) of the string provided for host is actually used. the absolute paths for the API are hardcoded.

@zachoooo
Copy link
Author

zachoooo commented Dec 6, 2020

Yes my reverse proxy is trimming the prefixes. qBittorrent currently doesn't support base urls, so I have to trim it to make it available through the reverse proxy. There is an issue open for it on qBittorrent: qbittorrent/qBittorrent#5693

It has been open for quite some time though, so I don't know when that feature will be added. It's possible that this could be considered an upstream issue. Anyways here is the command:

curl http://192.168.1.69/qBittorrent/api/v2/app/version --cookie "[BROWSER COOKIE]"

I copied the cookie from my browser after logging in through the Web UI. I didn't want to include it in case it contained any sensitive information, but the output does work.

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100     6  100     6    0     0   6000      0 --:--:-- --:--:-- --:--:--  6000
v4.3.1

@rmartin16
Copy link
Owner

hmm....even if they supported a base url, i still think this client would be broken....since it'll always send the default paths....unless qbittorrent just accepted either i guess.

in theory, it wouldn't be too hard to prefix the API path with any user provided base path. just a little concerned that could be a breaking change to some users if they are randomly including a path in their instantiations right now....seems pretty unlikely though.

i can at least mock something up in the next few days. thanks for letting me know.

@zachoooo
Copy link
Author

zachoooo commented Dec 6, 2020

I guess this is probably better addressed upstream by qBittorrent devs. I can always just use Docker DNS to connect to the API endpoints directly instead of using a reverse proxy. Thanks for looking at it so quickly though!

rmartin16 added a commit that referenced this issue Dec 6, 2020
 - Allows users to leverage this client when qBittorrent is configured behind a reverse proxy.
  - For instance, if the Web API is being exposed at "http://localhost/qbt/", then users can instantiate via Client(host='localhost/qbt') and all API endpoint paths will be prefixed with "/qbt".
 - Additionally, the scheme (i.e. http or https) from the user will now be respected as the first choice for which scheme is used to communicate with qBittorrent.
  - However, users still don't need to even specify a scheme; it'll be automatically determined on the first connection to qBittorrent.
 - Neither of these should be breaking changes, but if you're instantiating with an incorrect scheme or an irrelevant path, you may need to prevent doing that now.
@rmartin16
Copy link
Owner

@zachoooo, I released v2020.12.14. It should now support your instantiation below and make calls using /qBittorrent at the base of the path. Please let me know if you run in to any problems. Thanks.

qbt_client = qbittorrentapi.Client(host='http://[HOST]/qBittorrent/', username='[USERNAME]', password='[PASSWORD]')

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

No branches or pull requests

2 participants