Danie1 / threads-api

Unofficial Python API for Meta's Threads App
https://pypi.org/project/threads-api/
MIT License
108 stars 15 forks source link

Uploading post with image doesn't work anymore since today #60

Open dfkt opened 11 months ago

dfkt commented 11 months ago

Uploading posts with image worked fine for a few days (even though Instagram/Threads complained via email every time about my bot being hosted in a different country, and I checked in the security setting that it's fine that way).

I've tried all three HTTP session classes in the threads-api, it makes no difference. Threads returns an error, and an HTML page twice, displaying "this page does not exist".

Full error log incl. HTML is attached below.

Oops, this is an error that hasn't yet been properly handled.
Please open an issue on Github at https://github.com/Danie1/threads-api.
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.11/site-packages/threads_api/src/threads_api.py", line 168, in _extract_response_json
    resp = json.loads(response)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/bot.py", line 164, in <module>
    asyncio.run(main())
  File "/app/.heroku/python/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/app/bot.py", line 159, in main
    await post_include_image(api) # Posts a message with an image.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/bot.py", line 138, in post_include_image
    result = await api.post("#bot", image_path=download_img)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/site-packages/threads_api/src/threads_api.py", line 107, in wrapper
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/site-packages/threads_api/src/threads_api.py", line 1131, in post
    res = await self._private_post(url=post_url, headers=headers,data=payload)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/site-packages/threads_api/src/threads_api.py", line 107, in wrapper
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/site-packages/threads_api/src/threads_api.py", line 181, in _private_post
    resp_json = self._extract_response_json(response)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/site-packages/threads_api/src/threads_api.py", line 173, in _extract_response_json
    raise Exception(f'Failed to decode response [{response}] as JSON.\n\n{OPEN_ISSUE_MESSAGE}')
Exception: Failed to decode response [<!DOCTYPE html>

threads-api-error.txt

Danie1 commented 11 months ago

Hey @dfkt, my first thoughts were that maybe the API broke, but then I posted successfully a multiple-image post and a single image post right now. I checked the other APIs on Github and no one reported this yet.

My second thoughts were that maybe you're no longer authenticated, but I see that in the HTML you sent it says "logged-in", and usually when the user isn't authenticated on this page it reads "not-logged-in". So then it's most probably not the case either.

Can you please try setting the "LOG_LEVEL" to "DEBUG" (as specified in the README) and attach the request that had failed? Which version of threads-api are you using? Have you been using multiple accounts with the API?