-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: translators.server.TranslatorError: Unable to connect the Internet. #110
Comments
Opening python and attempting to import translators results in the same error. |
There are only two reasons. One is your Internet. You can use python to test other web requests, such as requesting any web page to see if they work. The second is to test the link and see if you can get the results properly. The link results indicate which service area your network belongs to. |
Maybe it's about proxy? \site-packages\translators\server.py @property
def get_server_region(self):
_headers_fn = lambda url: self.get_headers(url, if_api=False, if_referer_for_host=True)
try:
try:
data = eval(requests.get(self.get_addr_url, headers=_headers_fn(self.get_addr_url)).text[9:-2])
sys.stderr.write(f'Using state {data.get("stateName")} server backend.\n')
return data.get('country')
except requests.exceptions.Timeout:
ip_address = requests.get(self.get_ip_url, headers=_headers_fn(self.get_ip_url)).json()['origin']
form_data = {'ip': ip_address, 'accessKey': 'alibaba-inc'}
data = requests.post(url=self.ip_tb_add_url, data=form_data, headers=_headers_fn(self.ip_tb_add_url)).json().get('data')
return data.get('country_id')
except requests.exceptions.ConnectionError:
raise TranslatorError('Unable to connect the Internet.\n')
except:
warnings.warn('Unable to find server backend.\n')
country = self.default_country or input('Please input your server region need to visit:\neg: [Qatar, China, ...]\n')
sys.stderr.write(f'Using country {country} server backend.\n')
return 'CN' if country == 'China' else 'EN' requests.get() 'proxies' is missing, if i modify to: (my proxy is 127.0.0.1:7890) data = eval(requests.get(self.get_addr_url, headers=_headers_fn(self.get_addr_url), proxies={'http': '127.0.0.1:7890', 'https': '127.0.0.1:7890'}).text[9:-2]) it works So I think the problem locates at: class TranslatorsServer:
def __init__(self):
self.server_region = GuestSeverRegion().get_server_region the method get_server_region could not use proxy And when I close proxy, the problem is gone. |
@akynazh |
Attempting to connect to this site results in this on my network... however in Tor this is what I get |
@UlionTse #26307 fixes wrong parsing of Windows registry proxy settings in 2022.5.12, and I find that some python3.10(like python3.10.4) is before that date. So maybe the problem is here. My python version is 3.10.9, which is published on 2022.12.6, the bug had been fixed. |
@IveMalfunctioned |
Changing Firefox's proxy settings from 'Use system proxy settings' to 'No proxy' seems to have fixed the link, however my system isn't using a proxy, so that's kinda weird. The problem still persists. My Python version is |
@IveMalfunctioned |
I know, I was just showing that it at least connected to the site with Tor, and on my browser it didn't connect at all. |
@IveMalfunctioned |
Yeah I know, I was showing you that my internet wasn't working with the site, so it was either my network or computer. |
@IveMalfunctioned Please upgrade version to 5.6.0 |
Problem was fixed by reinstalling in command prompt: |
@UlionTse can you explain a bit more as to why the following line:
fixes the issue? I'm using
|
Hello, bro. Based on that, can you load this |
@SeanDunford os.environ['translators_default_region'] = 'xxx' skips IP identification. Which country or region are you in? I would like to know which region does not have access to this network address, thanks. |
In nyc and the ip lookup site does work. |
@SeanDunford Bro, please |
Debug Tips
What happened?
When attempting to use the library, I get an error telling me it can't connect to the internet. My machine is connected to the internet just fine, so it seems to be an issue with the library.
APP Version
5.5.6
Python Version
3.10
Runtime Environment
Windows 10
Country/Region
United States
Relevant log output
https://gist.github.com/IveMalfunctioned/a320099163faf78d6af138278ca522ef
Screenshots
Code of Conduct
The text was updated successfully, but these errors were encountered: