0

I am trying to send a file to the server using the Requests library in python. I have tried using the snippet from POSTMAN API. I am providing the program sample for reference. This is the `import requests

import requests
from requests.auth import HTTPBasicAuth
from requests.packages.urllib3.exceptions import InsecureRequestWarning
#from urllib3 import disable_warnings

url = "https://jazz,xxx.de/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/<Project_Area>/attachment/"
filepath ="D:\\ETM\\varaiblelist.txt"
#headers = {"Content-Type": "multipart/form-data; boundary=<calculated when request is sent>","Content-Length":"<calculated when request is sent>","Accept":"*/*", "Accept-Encoding":"gzip, deflate, br"}
headers = {"Content-Type": "boundary=multipart/<multipart type>","Accept":"/"}

with open(filepath, 'rb') as fobj:
response = requests.post(url, headers=headers, files={'file': fobj},auth = HTTPBasicAuth('xxxx', 'xxxxx'), verify = False)

print(response)
print(response.headers)

POSTMAN snippet copied. The output is:

<Response [201]> {'Date': 'Thu, 12 Jan 2023 06:07:45 GMT', 'X-Powered-By': 'Servlet/3.0', 'Strict-Transport-Security': 'max-age=31536000', 'Content-Location': 'slug__xxxxx', 'Location': 'https://jazz.xxx.de/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/<Project_Area>/attachment/slug__xxxxx', 'Expires': 'Thu, 01 Dec 1994 16:00:00 GMT', 'Cache-Control': 'no-cache="set-cookie, set-cookie2"', 'Set-Cookie': 'JSA_SESSION_IDENTITY=xxxx; Path=/qm1; Secure; HttpOnly; SameSite=None;, JSESSIONID=xxxxxxxx; Path=/; Secure; HttpOnly; SameSite=None;', 'Content-Length': '0', 'Keep-Alive': 'timeout=5, max=100', 'Connection': 'Keep-Alive', 'Content-Language': 'en-US'}

It is able to create but when I use the Content-Location URL. It says Address not found. I am not able to solve this issue.

dell rawal
  • 11
  • 5

0 Answers0