python-ubersmith icon indicating copy to clipboard operation
python-ubersmith copied to clipboard

Redirect isn't caught

Open solomongifford opened this issue 11 years ago • 2 comments

This api implementation does not respond to redirects very well. For example, lets say you have a site that redirects all traffic from http://ubersmith.site to https://ubersmith.site and the client uses the http://ubersmith.site url. In my case, this api responded with messages indicating missing parameters.

It appears the requests module redirects with a GET instead of a POST if the webserver responds with a 301 or 302 but redirects correctly if a 307 is returned. However, the 307 is not implemented often by web admins.

The result is that the contents of the post are lost and the webserver responds as if the method is valid but with missing parameters.

I think the solution is simply to add "allow_redirects=False" to the requests.post in the _send_request method in api.py. At that point we should check the response - if its a 307, go ahead and post to the new url, otherwise, respond that the webserver attempted to redirect in manner that is not supported by ubersmith.

solomongifford avatar Oct 31 '14 17:10 solomongifford

Ah, that's interesting! I believe your solution is the correct way to go just to give an intuitive error message. However the root problem is that the request handler should be configured with the correct https:// URL from the get go. If you want to submit a patch I will merge.

jasonkeene avatar Feb 22 '15 19:02 jasonkeene

Also, sorry for not responding sooner. I was on my honeymoon in Thailand when you posted :tropical_drink:

jasonkeene avatar Feb 22 '15 19:02 jasonkeene