0
req2 = requests.put(url, json = json_data, headers= header)
print(req2.status_code)
print(req2.headers)

Where json_data = req1.json()

url = 'some url'

and

header = {'Content-Type': 'application/data;charset=UTF-16'}

In above code req1 gets a response from a server.
req1 json is passed with url to fetch response req2. I want to make req2 using PUT() with charset = utf-16. When I am trying to do this by setting headers of req2 (1st line of code) it doesn't do anything as still the statement print(req2.headers) prints

{'Date': 'Thu, 01 Mar 2018 09:51:00 GMT', 'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json;charset=UTF-8'}

2 Answers 2

1

If I'm correct, req2.headers shows the response headers. You are setting the Content-Type of your request header, showing that the content you are sending is encoded in UTF-16. I don't think the response must have the same encoding as the request, it is up to the server to decide.

Sign up to request clarification or add additional context in comments.

Comments

1

You should use the Accept-Charset header to say what content type you wish to receive:

Accept-Charset: utf-8

The server can still ignore you. Usually it's not a problem as Requests will decode the response for you if you use the response.text field.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.