user9028316
user9028316

Reputation:

Invalid content type encoding python

Everyone!

I'm trying to request from an API in python like so:

    headers = {"Content-Type": "application/json", "user-key": self.api_key}
    params = {self.filter_fields: '*', self.filter_date: self.date_millis, self.limit: '2'}
    request = requests.get(self.api_endpoint, headers=headers, params=params)

I double checked and see no problem with my filters nor api key. The problem is that when the I print the request content "print(request.json())" I get this following error:

{'Err': {'status': 400, 'message': "Invalid content encoding please change 'Content-Type' header."}}

Upvotes: 0

Views: 1204

Answers (1)

mhawke
mhawke

Reputation: 87114

The code performs a GET request. It specifies that the content type is JSON, however, there is no JSON content being passed in the body of the request.

Try omitting the content-type header.

Another possibility is to pass the parameters using the json parameter. The content-type does not need to be set in the headers, requests will send it automatically:

headers = {"user-key": self.api_key}
params = {self.filter_fields: '*', self.filter_date: self.date_millis, self.limit: '2'}
response = requests.get(self.api_endpoint, headers=headers, json=params)

Upvotes: 1

Related Questions