문제

I've recently been getting a 400 bad request parse error when making a request to my timeline_url.

Im posting to this url timeline_url = 'https://www.googleapis.com/mirror/v1/timeline'

EDIT Here is the code:

    headers = {'Content-Type': 'application/json',
               'Authorization' : 'Bearer %s' % access_token}
    body = {"text" : "Waddup doe!"}
    """ ***********THIS IS RETURNING ERROR 400 PARSE ERROR***********"""
    send_request(timeline_url, headers, 'POST',body)

The send_request method is using requests

req = requests.post(url, data=body, headers=headers)

I'm just trying to insert plain text to my timeline.

도움이 되었습니까?

해결책

body_bytes = sys.getsizeof(body)
headers['Content-Length'] = body_bytes

This is inserting an incorrect value into your request headers. sys.getsizeof describes how large the data structure is -- including pointers, counters, etc. It does NOT describe how many bytes the string representation takes on the HTTP stream.

Just delete these lines; requests will fill in Content-Length automatically.


You don't describe how you json-encode the payload. Perhaps you need to do this:

req = requests.post(url, data=json.dumps(body), headers=headers)

See: http://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top