twintproject / twint

An advanced Twitter scraping & OSINT tool written in Python that doesn't use Twitter's API, allowing you to scrape a user's followers, following, Tweets and more while evading most API limitations.
MIT License
15.66k stars 2.72k forks source link

[QUESTION]Correct code raised unexpected exception (under vpn) #618

Closed AnthonyChouGit closed 4 years ago

AnthonyChouGit commented 4 years ago

Issue Template

Please use this template!

Initial Check

If the issue is a request please specify that it is a request in the title (Example: [REQUEST] more features). If this is a question regarding 'twint' please specify that it's a question in the title (Example: [QUESTION] What is x?). Please only submit issues related to 'twint'. Thanks.

Done.

Make sure you've checked the following:

Done.

Command Ran

Please provide the exact command ran including the username/search/code so I may reproduce the issue.

import twint

c = twint.Config()
c.Username = "noneprivacy"
c.Search = "#osint"

twint.run.Search(c)

Description of Issue

Please use as much detail as possible.

I'm running this code under a vpn since twitter is blocked in my area. The vpn software is ShadowSocksR, and it works nicely in all other cases. But when I ran the code above, an exception occurred. It seems that it failed to connect to twitter due to some network problem. For your information, I'll provide the log below.

CRITICAL:root:twint.get:User:Cannot connect to host twitter.com:443 ssl:True [Connect call failed ('69.171.245.49', 443)]
Traceback (most recent call last):
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\site-packages\aiohttp\connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 954, in create_connection
    raise exceptions[0]
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 941, in create_connection
    await self.sock_connect(sock, address)
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\asyncio\selector_events.py", line 464, in sock_connect
    return await fut
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\asyncio\selector_events.py", line 494, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
TimeoutError: [Errno 10060] Connect call failed ('69.171.245.49', 443)

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

Traceback (most recent call last):
  File "C:/Users/antho/PycharmProjects/Graduation/1221.py", line 8, in <module>
    twint.run.Search(c)
  File "c:\windows\system32\src\twint\twint\run.py", line 288, in Search
    run(config, callback)
  File "c:\windows\system32\src\twint\twint\run.py", line 209, in run
    get_event_loop().run_until_complete(Twint(config).main(callback))
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 579, in run_until_complete
    return future.result()
  File "c:\windows\system32\src\twint\twint\run.py", line 150, in main
    await task
  File "c:\windows\system32\src\twint\twint\run.py", line 194, in run
    await self.tweets()
  File "c:\windows\system32\src\twint\twint\run.py", line 133, in tweets
    await self.Feed()
  File "c:\windows\system32\src\twint\twint\run.py", line 49, in Feed
    response = await get.RequestUrl(self.config, self.init, headers=[("User-Agent", self.user_agent)])
   File "c:\windows\system32\src\twint\twint\get.py", line 119, in RequestUrl
    response = await Request(_url, params=params, connector=_connector, headers=headers)
  File "c:\windows\system32\src\twint\twint\get.py", line 143, in Request
    return await Response(session, url, params)
  File "c:\windows\system32\src\twint\twint\get.py", line 148, in Response
    async with session.get(url, ssl=True, params=params, proxy=httpproxy) as response:
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\site-packages\aiohttp\client.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\site-packages\aiohttp\client.py", line 483, in _request
    timeout=real_timeout
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\site-packages\aiohttp\connector.py", line 523, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\site-packages\aiohttp\connector.py", line 859, in _create_connection
req, traces, timeout)
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\site-packages\aiohttp\connector.py", line 1004, in _create_direct_connection
    raise last_exc
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\site-packages\aiohttp\connector.py", line 986, in _create_direct_connection
    req=req, client_error=client_error)
  File "C:\Users\antho\AppData\Local\Programs\Python\Python37\lib\site-packages\aiohttp\connector.py", line 943, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host twitter.com:443 ssl:True         [Connect call failed ('69.171.245.49', 443)]

Process finished with exit code 1`

Environment Details

Using Windows, Linux? What OS version? Running this in Anaconda? Jupyter Notebook? Terminal? My OS is Windows 10, and I'm running the code in PyCharm.

pielco11 commented 4 years ago

It does not seem related to Twint itself, rather to the VPN

I do suggest you to either change the VPN or ask for a friend to get the data that you need

Closing since it's not related to Twint