mr0re1 / pynstagram

Python library that allows you to upload photos to instagram
145 stars 34 forks source link

Pynstagram worked great: now returning IOError #19

Closed commadelimited closed 6 years ago

commadelimited commented 8 years ago

I used Pynstagram successfully for a few weeks, but now it's returning the following error:

IOError: Please update your Instagram app to continue posting photos

I haven't changed anything on my end. Is it possible that Instagram has changed something on theirs? I've tried both as a module and using the CLI. I've logged into my account fresh to make sure that my credentials were correct.

Do you have any suggestions?

Here's the full stack trace:

Traceback (most recent call last):
  File "/Users/andymatthews/.virtualenvs/website/bin/pynstagram", line 9, in <module>
    load_entry_point('pynstagram==0.1.3', 'console_scripts', 'pynstagram')()
  File "/Users/andymatthews/.virtualenvs/website/lib/python2.7/site-packages/pynstagram/__main__.py", line 28, in main
    client.upload(options.file, text)
  File "/Users/andymatthews/.virtualenvs/website/lib/python2.7/site-packages/pynstagram/client.py", line 17, in upload
    self._session.configure_photo(media_id, caption)
  File "/Users/andymatthews/.virtualenvs/website/lib/python2.7/site-packages/pynstagram/session.py", line 95, in configure_photo
    raise IOError(resp_json.get('message'))
IOError: Please update your Instagram app to continue posting photos
mr0re1 commented 8 years ago

Thank you for your feedback, looking at this problem.

mr0re1 commented 8 years ago

Closed by mistake, reopen.

mr0re1 commented 8 years ago

Fixed, version 1.4 is published.

commadelimited commented 8 years ago

Hey Ivan, first off, this was ridiculously fast, thank you so much. Second, it's still doing the same thing for me. A pip freeze shows pynstagram==0.1.4, but I'm getting the same error both with the command line, and as a module:

Traceback (most recent call last):
  File "/Users/andymatthews/.virtualenvs/website/bin/pynstagram", line 9, in <module>
    load_entry_point('pynstagram==0.1.4', 'console_scripts', 'pynstagram')()
  File "/Users/andymatthews/.virtualenvs/website/lib/python2.7/site-packages/pynstagram/__main__.py", line 28, in main
    client.upload(options.file, text)
  File "/Users/andymatthews/.virtualenvs/website/lib/python2.7/site-packages/pynstagram/client.py", line 17, in upload
    self._session.configure_photo(media_id, caption)
  File "/Users/andymatthews/.virtualenvs/website/lib/python2.7/site-packages/pynstagram/session.py", line 95, in configure_photo
    raise IOError(resp_json.get('message'))
IOError: Please update your Instagram app to continue posting photos

Is there also something I need to do within the Instagram app, or with pip?

commadelimited commented 8 years ago

BTW, this is an awesome project, thanks so much for creating it. Too bad Instagram makes this simple thing so difficult.

mr0re1 commented 8 years ago

@commadelimited could you please confirm that file /Users/andymatthews/.virtualenvs/website/lib/python2.7/site-packages/pynstagram/session.py contains change 7785ba4a969945f635b7e079f226fe6e1ed1f3c6 .

I've updated package on my machine and verified, it works for me.

mr0re1 commented 8 years ago

@commadelimited , I can imagine another reason, right now user-agent version is randomized.

inst_version = '.'.join([str(p) for p in ['5', randint(1, 2), randint(0, 2)]])

Probably you had a bad luck with random. Going to figure out versions set that works and update this issue.

commadelimited commented 8 years ago

Here's the generate_user_agent method from session.py:

def generate_user_agent():
    ver = random.choice(VERSIONS)
    res = random.choice(RESOLUTIONS)
    dpi = random.choice(DPIS)

    inst_version = '.'.join([str(p) for p in ['5', randint(1, 2), randint(0, 2)]])
    and_version = str(randint(10, 11)) + '/' + '.'.join([str(p) for p in [randint(1, 3), randint(3, 5), randint(0, 5)]])

    return 'Instagram %s Android (%s; %s; %s; samsung; %s; %s; smdkc210; en_US)' % \
           (inst_version, and_version, dpi, res, ver, ver)

Looks to be a match.

commadelimited commented 8 years ago

Just tried again with CLI and module and getting the same results. I put a breakpoint in session.py at line 23 and got these results if it helps:

ipdb> inst_version
'5.2.0'
ipdb> and_version
'10/1.4.5'
mr0re1 commented 8 years ago

@commadelimited , it's very strange, have tried same versions (5.2.0, 10/1.4.5). Works fine for me.

mr0re1 commented 8 years ago

@commadelimited , another reason I could imagine is Instagram partially deployed new API-endpoints, and you belong to part of customers who belong to it, and I'm not, thats why service behaves differently for us.

commadelimited commented 8 years ago

Interesting. Is there anything else I can try (hardcode) from within session.py to alter the effects?

sholoma commented 8 years ago

Same problem File "build/bdist.linux-x86_64/egg/pynstagram/session.py", line 95, in configure_photo IOError: Please update your Instagram app to continue posting photos

mr0re1 commented 8 years ago

Checked it again today, still works fine for me. Going to try to create another account, may be this will help me to reproduce it.

PatGW commented 8 years ago

@mr0re1 second the thanks above from @commadelimited. Also been trying to find a solution to this issue. Looking forward to seeing your latest comments.

commadelimited commented 8 years ago

Thank you @mr0re1! Please let me know if I can help in any way.

mr0re1 commented 8 years ago

Have tried other accounts, wasn't able to reproduce it. Keep looking.

mr0re1 commented 8 years ago

@commadelimited , thank you. Could you please try other version 6.x.x, 7.x.x ?

kdekooter commented 8 years ago

I have tried with 6.x.x and 7.x.x but no change.

kdekooter commented 8 years ago

I tried to use the user agent string that my phone produces: Instagram 8.3.0 Android (23/6.0.1; 420dpi; 1080x1794; LGE/google; Nexus 5X; bullhead; bullhead; en_US) but the problem remains.

javilumbrales commented 8 years ago

Hi there, thanks for this great work @mr0re1! Just in case it helps, I've got a few accounts and it works for one of them, but it doesn't for the other two, not quite sure what's the difference but seems to be consistent. If useful I wouldn't mind sending you the details of one of my "non-working" accounts.

mr0re1 commented 8 years ago

@kdekooter , how did you get this User-agent string, are you able to sniff applications traffic?

kdekooter commented 8 years ago

@mr0re1 yes I used an app called "tPacketCapture" to capture traffic while I was adding a photo in the Instagram app. After that I analyzed the resulting .pcap file on my mac using Wireshark.

mr0re1 commented 8 years ago

@kdekooter how did you handle to decrypt it? I believe Instagram client uses SSL.

kdekooter commented 8 years ago

I did not ;-). I was just sniffing the headers going out.

mr0re1 commented 8 years ago

Took some investigations. Looks like instagram changed some API methods signatures, keep looking.

mr0re1 commented 8 years ago

Was able to reproduce this behavior, working on fix.

commadelimited commented 8 years ago

Yeah! Nicely done Ivan!

On Jun 22, 2016, at 5:51 PM, Ivan Orlov notifications@github.com wrote:

Was able to reproduce bug, working on fix.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

mr0re1 commented 8 years ago

Found nice alternative to Pynstagram mgp25/Instagram-API, it's written on PHP, but I hope it may unblock you meanwhile I fix Pynstagram.

I've tried it, works for me, uses new api version.

ydatech commented 8 years ago

same problem "Your version of Instagram is out of date. Please upgrade your app to log in to Instagram."

PatGW commented 8 years ago

@ydatech Did you get the same issue with Pynstagram or using the PHP alternative: https://github.com/mgp25/Instagram-API ?

ydatech commented 8 years ago

@PatGW Pynstagram..

I tried to edit session.py like this:

def generate_user_agent():
    return 'Instagram 8.2.0 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)'       

def generate_signature(data):
    #b4a23f5e39b5929e0666ac5de94c89d1618a2916
    return hmac.new(
            '55e91155636eaa89ba5ed619eb4645a4daf1103f2161dbfe6fd94d5ea7716095'.encode('utf-8'),
            data.encode('utf-8'), hashlib.sha256).hexdigest()

Base on mgp25/Instagram-API.. and it works while login but failed when tried to post photo..

kdekooter commented 8 years ago

In the PHP thing a csrftoken is retrieved from a cookie. I tried to implement this in the python code:

    def login(self, username, password):

        resp = self.session.get(self.ENDPOINT_URL + '/si/fetch_headers/?challenge_type=signup&guid=' + self.guid)
        csrftoken = resp.cookies.get('csrftoken')

        data = json.dumps({
            'phone_id': str(uuid.uuid1()),
            '_csrftoken': csrftoken,
            'username': username,
            'guid': self.guid,
            'device_id': self.device_id,
            'password': password,
            # 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'login_attempt_count': '0'
        })

        sig = generate_signature(data)

        payload = 'signed_body=%s.%s&ig_sig_key_version=4' % (sig, urllib.quote(data))
        resp = self.session.post(self.ENDPOINT_URL + '/accounts/login/', payload)
        resp_json = resp.json()

        if resp_json.get('status') != 'ok':
            raise IOError(resp_json.get('message'))

Unfortunately the problem remains. I may have overlooked something...

javilumbrales commented 8 years ago

I was having a look at the code and have a play with it comparing it with the PHP lib but had no luck. Once thing I noticed though, is that right after uploading a picture with mgp25/Instagram-API, I was able to upload another one with pynstagram without any code changes. Not sure if it's related with the fact that the php lib does many additional requests before actually uploading the picture.. I'll keep digging.

vkudyushev commented 8 years ago

So, I've used this package with Python 2.7.6 before apeared an Error, then I've updated Python version to 2.7.9 on my Desktop (Windows 10, 64-bit) and it workes good, but on server with Ubuntu 14.04 LTS 64-bit doesn't. Then I've tried to edit quotes in code from

with pynstagram.client('username', 'password') as client: client.upload('/img/insta.jpg', u"some caption")

to with pynstagram.client("username", "password") as client: client.upload("/img/insta.jpg", u"some caption")

and now it works good on Ubuntu too! Maybe it'll helps anybody

added: not all accounts works on Ubuntu...

p.s.: sorry for my poor English...

PatGW commented 8 years ago

@vadimk-design and you can now post to Instagram without the wrong version of Instagram error?

jegue commented 8 years ago

No lucky on this?

vkudyushev commented 8 years ago

@PatGW so, on my 2 computers with Windows 10 (64-bits both) library is working great with all accounts that I have (my private and few business). On one computer installed Python v 2.7.10 and on another - Python v 2.7.11, Pynstagram v0.1.4 - on both.

But on VDS with Ubuntu 14.04 (64-bit, Python v 2.7.11, Pynstagram v0.1.4) pynstagram can post without erros only to my private account, posting to businness accounts gives error (please update your Instagram app...). I don't understand why it's happening...

VDigitall commented 8 years ago

І have same problem on my Windows PC x64 and Mint Cinnamon 17.3 x64 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\pynstagram\__init__.py", line 5, in client return PynstagramClient(*args, **kwargs) File "C:\Python27\lib\site-packages\pynstagram\client.py", line 7, in __init__ self._session.login(username, password) File "C:\Python27\lib\site-packages\pynstagram\session.py", line 59, in login raise IOError(resp_json.get('message')) IOError: Your version of Instagram is out of date. Please upgrade your app to log in to Instagram. try change version from 5 to 9. Nothings change.

ronaldjeremy commented 8 years ago

IOError: Your version of Instagram is out of date. Please upgrade your app to log in to Instagram.

drew222 commented 8 years ago

IOError: Your version of Instagram is out of date. Please upgrade your app to log in to Instagram.

kdekooter commented 8 years ago

New keys just in: b5d839444818714bdab3e288e6da9b515f85b000b6e6b452552bfd399cb56cf0, app version 8.5.1. (borrowed from https://github.com/huttarichard/instagram-private-api/blob/master/client/v1/constants.js)

Just replacing them does not seem to work for me however. Probably some more stuff has changed.

roperi commented 8 years ago

Any good news?

jakeingit commented 8 years ago

Does anyone have any updates on this issue? Thanks in advance!

yaghmaie commented 8 years ago

https://github.com/mgp25/Instagram-API seems to work and used in Instagraph (unofficial Instagram for Ubuntu Phone) http://www.omgubuntu.co.uk/2016/07/instagraph-unofficial-instagram-app-ubuntu-phone

b3nab commented 7 years ago

@yaghmaie Sounds interesting.. anyone who wants to help me rewrite this API in Python 2.x/3.x? Maybe with some hints we could bring back to life this API

kdekooter commented 7 years ago

@b3nab I just submitted some hints ;-)

b3nab commented 7 years ago

@kdekooter Great! And now the upload return to work again? I am not at home to check your pull request :)

kdekooter commented 7 years ago

Works for me anyway

sholoma commented 7 years ago

Confirm, pull request works! @kdekooter cool job, thank you!