atlassian-python-api icon indicating copy to clipboard operation
atlassian-python-api copied to clipboard

HTTP Redirect Will Cause POST/PUT/etc. Methods to Fail

Open joealam opened this issue 7 years ago • 1 comments

Trying to use any of the API methods that use anything other than the GET HTTP method will confusingly fail if the URL is redirected from http to https (which is a common default behaviour).

The reason this is a little harder to track down, is that due to the API layout you will typically be redirected to a "get list of" version of whatever was trying to be submitted.

For example, I discovered this while trying to submit comments:

jira = Jira(
        url='http://myjiraurl.atlassian.net',
        username='myscriptuser',
        password='myscriptpassword')
response = jira.issue_add_comment('TST-123', 'Example comment')

The comment will not be added, and instead I will get a HTTP 200 response with a body something like the following:

{"startAt":0,"maxResults":1048576,"total":0,"comments":[]}

After some custom debug statements I discovered this is because it's internally handling the redirect from http://myjiraurl.atlassian.net to https://myjiraurl.atlassian.net, but in doing so it loses the POST method and ends up doing a GET.

According to the docs for python-requests it seems like this could be fixed by explicitly disabling automatic redirection on anything other than GET calls, and manually handling instead (meaning the method can be preserved).

If you’re using GET, OPTIONS, POST, PUT, PATCH or DELETE, you can disable redirection handling with the allow_redirects parameter

(https://2.python-requests.org/en/master/user/quickstart/#redirection-and-history)

joealam avatar Sep 16 '19 13:09 joealam

@joealam Looks like it's obsolete (based on the stats don't have many requests), if you still experiencing the problem. Please, provide a PR.

gonchik avatar Jan 03 '21 19:01 gonchik