instagrapi icon indicating copy to clipboard operation
instagrapi copied to clipboard

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

Open alirezaevil81 opened this issue 1 year ago • 5 comments

I get this error after using any direct sending method

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

  • OS: windows 11
  • Python version 3.12.2
  • instagrapi version 2.0.3

alirezaevil81 avatar Mar 03 '24 08:03 alirezaevil81

Hi @alirezaevil81

Could you provide your code that returns this error?

uw935 avatar Mar 03 '24 21:03 uw935

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'

caiopedroso avatar Mar 07 '24 13:03 caiopedroso

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"]

Maherstad avatar Mar 08 '24 14:03 Maherstad

same problem here, this used to work now this error occurs

ospr420 avatar Mar 09 '24 15:03 ospr420

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.

instaprime avatar Mar 10 '24 20:03 instaprime

@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.

claell avatar Apr 10 '24 10:04 claell