ping / instagram_private_api

A Python library to access Instagram's private API.
MIT License
2.94k stars 608 forks source link

how does chaging a profile picture work? #383

Open verfluecht opened 2 years ago

verfluecht commented 2 years ago

Before submitting an issue, make sure you have:

Which client are you using?


Describe your Question/Issue:

I'm new to python and was playing around with how to change my Instagram profile picture. The part I just can't get past is how I can put my image into the program.


Code:

from instagram_private_api import Client, ClientCompatPatch

user_name = 'my_username'
password = 'my_password'
api = Client(user_name, password)

with open("image.png", "rb") as f:
    api.change_profile_picture(f.read())

Error/Debug Log:

Error parsing error response: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/instagram_private_api/endpoints/accounts.py", line 152, in change_profile_picture
    response = self.opener.open(req, timeout=self.timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 563, in error
    return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

Why does it say Bad Request ? Do I have to do something with the image? Or input it in another way? In the documentation, the parameter is described as photo_data – byte string of image but I don't really know if the way I did is correct.