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

Issue with post creation #43

Closed Xehos closed 11 months ago

Xehos commented 11 months ago

Hello, whenever I try to post a new Thread I'm getting this error right after message: INFO:Set logged-in state successfully. All set!

DEBUG:Starting new HTTPS connection (1): i.instagram.com:443
DEBUG:https://i.instagram.com:443 "POST /api/v1/media/configure_text_only_post/ HTTP/1.1" 404 21807
[ERROR]  Failed to decode response as JSON
Traceback (most recent call last):
  File "/home/sites/26a/0/09b25bf6df/.local/lib/python3.10/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/home/sites/26a/0/09b25bf6df/.local/lib/python3.10/site-packages/simplejson/__init__.py", line 514, in loads
    return _default_decoder.decode(s)
  File "/home/sites/26a/0/09b25bf6df/.local/lib/python3.10/site-packages/simplejson/decoder.py", line 386, in decode
    obj, end = self.raw_decode(s)
  File "/home/sites/26a/0/09b25bf6df/.local/lib/python3.10/site-packages/simplejson/decoder.py", line 416, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sites/26a/0/09b25bf6df/public_html/reqs.py", line 26, in post
    resp = response.json()
  File "/home/sites/26a/0/09b25bf6df/.local/lib/python3.10/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sites/26a/0/09b25bf6df/public_html/test.py", line 27, in <module>
    loop.run_until_complete(main())
  File "/usr/lib64/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/sites/26a/0/09b25bf6df/public_html/test.py", line 23, in main
    await post()
  File "/home/sites/26a/0/09b25bf6df/public_html/test.py", line 13, in post
    result = await api.post("Hello world!")
  File "/home/sites/26a/0/09b25bf6df/.local/lib/python3.10/site-packages/threads_api/src/threads_api.py", line 107, in wrapper
    return await func(self, *args, **kwargs)
  File "/home/sites/26a/0/09b25bf6df/.local/lib/python3.10/site-packages/threads_api/src/threads_api.py", line 1079, in post
    res = await self._private_post(url=post_url, headers=headers,data=payload)
  File "/home/sites/26a/0/09b25bf6df/.local/lib/python3.10/site-packages/threads_api/src/threads_api.py", line 107, in wrapper
    return await func(self, *args, **kwargs)
  File "/home/sites/26a/0/09b25bf6df/.local/lib/python3.10/site-packages/threads_api/src/threads_api.py", line 157, in _private_post
    return await self._auth_session.post(**kwargs)
  File "/home/sites/26a/0/09b25bf6df/public_html/reqs.py", line 32, in post
    raise Exception('Failed to decode response as JSON')
Exception: Failed to decode response as JSON

Does anyone know what should this one mean? Thanks

Danie1 commented 11 months ago

Hi, thanks for choosing threads-api :)

It means that the HTTP response you received from Threads.net is not as expected. One reason could be that the underlying authentication timed out or is no longer valid.

Please set LOG_LEVEL environment variable to DEBUG so you are able to see the full response. It usually hints as to why it had failed. You can run your script like this: LOG_LEVEL=DEBUG python3 main.py to include it.

If you need further assistance, please add additional details from the logs.

Danie1 commented 11 months ago

Please re-open with additional info if still reproduces after version v1.1.13 (https://github.com/Danie1/threads-api/releases/tag/v1.1.13). It contains improvements in this area / the solution, so at the very least it will be easier to troubleshoot if a different issue appears.