How to upload profile image with oauth and python


#1

I have my working code that can update my status for me but now i am testing to update my profile picture . And i have doubt I can able to update my profile image right ? Below is my code …

image_post = "https://api.twitter.com/1.1/account/update_profile_image.json?image={}".format(base64encode)
resp, content = client.request(image_post, "POST")
pprint.pprint(content)

Output :

'{"errors":[{"message":"Could not authenticate you","code":32}]}'

I looked into Twitter response-codes, they mention two follows …

  1. Could not authenticate you Your call could not be completed as dialed.
  2. Could not authenticate you Corresponds with a HTTP 401 - it means that your oauth_timestamp is either ahead or behind our acceptable range

Please somebody tell me how to resolve this ?

Note: (Django 1.7, Python 2.7, Python-oauth2, )

My question related to this but i damn sure my form have multipart …

After more digging before posting this i found in twitter documentation …

Timestamp
The oauth_timestamp parameter indicates when the request was created. This value should be the number of seconds since the Unix epoch at the point the request is generated, and should be easily generated in most programming languages. Twitter will reject requests which were created too far in the past, so it is important to keep the clock of the computer generating requests in sync with NTP.

So how to sync ?


**Updated:** Silly me Now i'm in office and getting different error
'{"request":"\\/1.1\\/account\\/update_profile_image.json?image=L2hvbWUvc2ltb24vbmlnaHR5YnVpbGQvcGFuYWZhY2UvcGFuYWZhY2UvbWVkaWEvdXBsb2Fkcy9yYWphc2ltb25AZ21haWwuY29tL0FUXzEucG5n","error":"not recognized."}'

This link they mention to use multipart/form-data or base64 encoded file.

So how to POST multipart that in request ?