subzeroid / instagrapi

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

[BUG] #1453

Closed zzcddd closed 1 year ago

zzcddd commented 1 year ago

I found a bug, when using the direct_send api, the parameter text will throw an exception when carrying an http link, the exception information is as follows:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\pythonProject3\pythonProject1\2023\7\10\venv\venv\lib\site-packages\instagrapi\mixins\private.py", line 535, in private_request
    raise e
  File "D:\pythonProject3\pythonProject1\2023\7\10\venv\venv\lib\site-packages\instagrapi\mixins\private.py", line 520, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "D:\pythonProject3\pythonProject1\2023\7\10\venv\venv\lib\site-packages\instagrapi\mixins\private.py", line 341, in _send_private_request
    response = self.private.post(
  File "D:\pythonProject3\pythonProject1\2023\7\10\venv\venv\lib\site-packages\requests\sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "D:\pythonProject3\pythonProject1\2023\7\10\venv\venv\lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\pythonProject3\pythonProject1\2023\7\10\venv\venv\lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "D:\pythonProject3\pythonProject1\2023\7\10\venv\venv\lib\site-packages\requests\adapters.py", line 510, in send
    raise RetryError(e, request=request)
requests.exceptions.RetryError: HTTPSConnectionPool(host='i.instagram.com', port=443): Max retries exceeded with url: /api/v1/direct_v2/threads/broadcast/link/ (Caused by ResponseError('too many 503 error responses'))

I trace the source code found that this piece of code has a problem,

if "http" in text:
    method = "link"
    kwargs["link_text"] = text
    kwargs["link_urls"] = dumps(re.findall(r"(https?://[^\s]+)", text))
else:
    kwargs["text"] = text

if the judgment is established, it will throw an exception, I hope the big guy help me solve it

adw0rd commented 1 year ago

@zzcddd cannot reproduce

>>> cl.direct_send("Link to https://gmail.com/ (test)", user_ids=[61054097570])
DirectMessage(id='31185384299056336558032414757093376', user_id=None, thread_id=340282366841710301244276020304025120547, timestamp=datetime.datetime(2023, 7, 28, 16, 51, 10, 341611, tzinfo=datetime.timezone.utc), item_type=None, is_sent_by_viewer=None, is_shh_mode=None, reactions=None, text=None, reply=None, link=None, animated_media=None, media=None, visual_media=None, media_share=None, reel_share=None, story_share=None, felix_share=None, xma_share=None, clip=None, placeholder=None)