subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.21k stars 667 forks source link

Error unsupported operand type(s) for //: 'str' and 'int' in send direct message for all options #1828

Open alirezaevil81 opened 6 months ago

alirezaevil81 commented 6 months ago

I get this error after using any direct sending method

Error unsupported operand type(s) for //: 'str' and 'int'

uw935 commented 6 months ago

Hi @alirezaevil81

Could you provide your code that returns this error?

caiopedroso commented 6 months ago

Hello, I'm encountering the same error. The code is quite straightforward:

from instagrapi import Client
cl = Client()
cl.login("USER", "PWD")
cl.direct_send('How are you?', user_ids=[cl.user_id])

Error:

    332 if xma_media_share:
    333     data["xma_share"] = extract_media_v1_xma(xma_media_share[0])
--> 335 data['timestamp'] = datetime.datetime.fromtimestamp(data['timestamp'] // 1_000_000)
    336 data['user_id'] = str(data['user_id'])
    338 return DirectMessage(**data)

TypeError: unsupported operand type(s) for //: 'str' and 'int'
Maherstad commented 6 months ago

refering to line 313 in extractor.py , function extract_reply_mesage :

wouldn't the following modification solve the problem ? int(data["timestamp"]) instead of data["timestamp"]

instaprime commented 6 months ago

Make sure to do a pip install instagrapi --upgrade

Then in extractors.py change this in line 335 : data['timestamp'] = datetime.datetime.fromtimestamp(data['timestamp'] // 1_000_000) to this : data['timestamp'] = datetime.datetime.fromtimestamp(int(data['timestamp']) // 1_000_000)

Also the next line seems to have a typo so change this data['user_id'] = str(data['user_id']) which returns a keyerror 'user_id'

change to this : data['user_id'] = str(data['id'])

Happy coding and good luck.

claell commented 5 months ago

@instaprime, if you already have a working solution, would you mind creating a PR for this? Then, it can get integrated in the code base, properly.