crustymonkey / py-sonic

A python library to wrap the Subsonic REST API
http://stuffivelearned.org/doku.php?id=programming:python:py-sonic
GNU General Public License v3.0
56 stars 26 forks source link

Unable to connect to subsonic install behind nginx proxy/redirect #16

Closed craftyguy closed 8 years ago

craftyguy commented 8 years ago

I am unable to successfully query a subsonic installation that is behind a nginx proxy/redirect over HTTPS. My subsonic install is very similar to what is outlined here in this guide, so that I'm able to use sane SSL/HTTPS settings and not the config that comes with subsonic. This setup is totally accessible via web browser and other subsonic applications (e.g. D-Sub on android).

If I remove subsonic from behind the proxy/redirect, I can connect to it from py-sonic.

Here's the relevant code in my application where it fails (I have tried other methods besides getArtists as well, they also fail with the same error)

          subConn = subsonicConn()                                                 
          subConn.connect(configOpts.get('Server','url'),                          
             configOpts.get('Server','username'),                                 
             configOpts.get('Server','password'),                                 
             configOpts.get('Server','port'))                                     

         self.artists = subConn.getArtists()

I do not want to supply my url, user, or pass for obvious reasons.. but if you'd like to reproduce this and test a possible solution please let me know and I'll create a guest account for you to test on my subsonic server.

Traceback when call to getArtists is made:

<libsonic.connection.Connection object at 0x7f8a4d4338d0>
Traceback (most recent call last):
  File "./vimsonic.py", line 198, in <module>
    if __name__ == '__main__': main()
  File "./vimsonic.py", line 49, in main
    playerInterface(player)
  File "./vimsonic.py", line 110, in __init__
    self.artists = subConn.getArtists()
  File "./vimsonic.py", line 173, in getArtists
    self.getIndexes()
  File "./vimsonic.py", line 184, in getIndexes
    self.indexes = self.conn.getIndexes()
  File "/usr/lib/python2.7/site-packages/libsonic/connection.py", line 361, in getIndexes
    res = self._doInfoReq(req)
  File "/usr/lib/python2.7/site-packages/libsonic/connection.py", line 2549, in _doInfoReq
    res = self._opener.open(req)
  File "/usr/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found

nginx config:

location /subsonic {                                                     
    proxy_set_header X-Real-IP         $remote_addr;                 
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;   
    proxy_set_header X-Forwarded-Proto https;                        
    proxy_set_header Host              $http_host;                   
    proxy_max_temp_file_size           0;                            
    proxy_pass                         http://127.0.0.1:4040;        
    proxy_redirect                     http:// https://;             
}         
craftyguy commented 8 years ago

I totally missed the multiple notes you had about using serverPath, so libsonic was constructing an invalid url. Sorry for the false bug :(