Request works in Postman but not using python codegen script

I am successfully using Postman to send a GET Request to a corp. Jira server*, which is a Windows server hosting a local instance of Jira within our corp. network. The response.text contains the expected data. For example at the beginning of the response, I see:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta name="application-name" content="JIRA" data-name="jira" data-version="9.4.7">
...
  • I edited the actual url to a simplified, anonymous string, and removed all auth/cookie info.

However (and this seems to be a common issue according to google), when I use the generated code snippet for python, instead of getting the expected response, I get something from Microsoft:

<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html dir="ltr" class="" lang="en">
<head>
    <title>Sign in to your account</title>
...
</head>

<body data-bind="some stuff">
    <script type="text/javascript">some more stuff</script>
</body>
</html>

Here is the generated code snippet:

import requests

url = "https://jira_server.com/issues/?jql=xxx"

payload = {}
files={}
headers = {
    'Authorization': 'Basic string',
    'Cookie': 'string'
}

response = requests.request("GET", url, headers=headers, data=payload, files=files)

print(response.text)

Note: I am sending the same authorization credentials via the script as is being sent by Postman - this is not a user-agent issue; I have tried it with user-agent set and the result is the same, which is that the response I am getting, appears to be from the server hosting Jira (or a dns server that redirects to the host?)

I have also tried adding all the headers that are present in Postman (including the user-agent), but no change.

Finally, I tried the following:
Python - http.client:

import http.client
import mimetypes
from codecs import encode

conn = http.client.HTTPSConnection("jira_server.com")
boundary = ''
payload = ''
headers = {
  'Authorization': 'Basic string',
  'Cookie': 'string',
  'Content-type': 'multipart/form-data; boundary={}'.format(boundary)
}
conn.request("GET", "/issues/?jql=xxx", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Response:
<!doctype html><html lang="en"><head><title>HTTP Status 500 – Internal Server Error</title>...</head></html>

Any assistance will be greatly appreciated, thx!

Hey @ktaggart :wave:

Welcome to the Postman Community! :postman:

As much as this is within Postman, it’s more of a python question and unless users have more knowledge around that language and the requests lib - It’s going to be difficult to help here. This might be better placed on Stackoverflow using the python tag :pray:

Have you managed to gain any information directly from the requests lib documentation?

In Postman, on the Settings tab for your request, check if you have the setting “Follow Authorization Header” enabled. If so, try disabling it and see if the Postman request still works. If it no longer works after changing the setting, then it’s a known behavior on python requests with no plan to change it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.