twikit icon indicating copy to clipboard operation
twikit copied to clipboard

httpx.ConnectTimeout

Open ruslawik opened this issue 1 year ago • 3 comments

Hello, guys! I installed twikit today and tried to authorize by a sample code, however I got an error as shown below. What is the problem? Снимок экрана 2024-07-15 в 16 40 07

I am using this code

import asyncio
from twikit import Client

USERNAME = 'i replaced it'
EMAIL = 'i replaced it'
PASSWORD = 'this one too'

client = Client('en-US')

async def main():
    await client.login(
        auth_info_1=USERNAME,
        auth_info_2=EMAIL,
        password=PASSWORD
    )
    client.save_cookies('twitter_cookies.json')

asyncio.run(main())

ruslawik avatar Jul 15 '24 11:07 ruslawik

Okay guys, the trouble was in proxy server, just made a new proxy and initialized it by:

# Initialize client
client = Client(language='en-US', proxy="http://ip:port")

ruslawik avatar Jul 15 '24 17:07 ruslawik

Getting the same ReadTimeout error sporadically. I can restart the script and get some succesful requests but it failed this way twice in the same hour. Not using a proxy. Getting this extra block on the traceback:

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/Documents/twikitToolset/followsDload.py", line 249, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/ubuntu/Documents/twikitToolset/followsDload.py", line 97, in main
    followList = await followList.next()  # Call next method to retrieve more tweets
  File "/usr/local/lib/python3.10/dist-packages/twikit/utils.py", line 56, in next
    return await self.__fetch_next_result()
  File "/usr/local/lib/python3.10/dist-packages/twikit/client/client.py", line 2440, in _get_user_friendship
    response, _ = await f(user_id, count, cursor)
  File "/usr/local/lib/python3.10/dist-packages/twikit/client/gql.py", line 456, in following
    return await self._friendships(user_id, count, Endpoint.FOLLOWING, cursor)
  File "/usr/local/lib/python3.10/dist-packages/twikit/client/gql.py", line 444, in _friendships
    return await self.gql_get(endpoint, variables, FEATURES)
  File "/usr/local/lib/python3.10/dist-packages/twikit/client/gql.py", line 114, in gql_get
    return await self.base.get(url, params=flatten_params(params), headers=headers, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/twikit/client/client.py", line 178, in get
    return await self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/twikit/client/client.py", line 119, in request
    response = await self.http.request(method, url, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/httpx/_client.py", line 1574, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.10/dist-packages/httpx/_client.py", line 1661, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.10/dist-packages/httpx/_client.py", line 1689, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.10/dist-packages/httpx/_client.py", line 1726, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/usr/local/lib/python3.10/dist-packages/httpx/_client.py", line 1763, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/usr/local/lib/python3.10/dist-packages/httpx/_transports/default.py", line 372, in handle_async_request
    with map_httpcore_exceptions():
  File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/dist-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout

dany27227 avatar Jul 15 '24 22:07 dany27227

Managed to run for 8 hours straight after re-logging in (deleting cookies.json). Might have been some instability from the twitter servers.

EDIT: Happened again after ~10 hours of running... Just noticed mine is a ReadTimeout while the OP's was a ConnectTimeout

Testing increasing the timeout to 10s in .../httpx/_config.py

dany27227 avatar Jul 16 '24 07:07 dany27227