Skip to content
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

Closed
2 tasks done
IveMalfunctioned opened this issue Feb 11, 2023 · 20 comments
Closed
2 tasks done

Comments

@IveMalfunctioned
Copy link

IveMalfunctioned commented Feb 11, 2023

Debug Tips

  • I'm sure I've read this project's Issues of README.

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

N/A

Code of Conduct

  • I agree to follow this project's Code of Conduct
@UlionTse
Copy link
Owner

Test the internet please.
translators20230213

@IveMalfunctioned
Copy link
Author

Opening python and attempting to import translators results in the same error.
https://gist.github.com/IveMalfunctioned/357713f6dce62e880a2b35657b4d1534

@UlionTse
Copy link
Owner

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.

@akynazh
Copy link

akynazh commented Feb 18, 2023

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.

This was referenced Feb 18, 2023
@UlionTse
Copy link
Owner

@akynazh requests self adapts to the local proxy environment. So wait for @IveMalfunctioned 's response.

@IveMalfunctioned
Copy link
Author

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.

Attempting to connect to this site results in this on my network...

image

however in Tor this is what I get

image

@akynazh
Copy link

akynazh commented Feb 19, 2023

@akynazh requests self adapts to the local proxy environment. So wait for @IveMalfunctioned 's response.

@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.

@akynazh
Copy link

akynazh commented Feb 19, 2023

@IveMalfunctioned
If you are using proxy, checking whether your python version is after 2022.5.12 may help.

@IveMalfunctioned
Copy link
Author

IveMalfunctioned commented Feb 19, 2023

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 3.11.1 which would be 2022.12.6.

@UlionTse
Copy link
Owner

@IveMalfunctioned
Computer network addresses have apparently been tampered with or overprotected by the use of tor. The existence of tor itself and access to the network address itself is the relationship between the spear and shield.

@IveMalfunctioned
Copy link
Author

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.

@UlionTse
Copy link
Owner

@IveMalfunctioned
Proxy or tor affects the network, which means that it affects your entire computer network, not just a browser. If you borrow a computer or mobile phone that has never used proxy or tor to open that page, you should have no problem now.

@IveMalfunctioned
Copy link
Author

Yeah I know, I was showing you that my internet wasn't working with the site, so it was either my network or computer.

@UlionTse
Copy link
Owner

UlionTse commented Mar 8, 2023

@IveMalfunctioned Please upgrade version to 5.6.0
Do this os.environ['translators_default_region'] = 'xxx' before import translators, and then we'll skip the previous question.

@UlionTse UlionTse reopened this Mar 8, 2023
@IveMalfunctioned
Copy link
Author

IveMalfunctioned commented Mar 27, 2023

Problem was fixed by reinstalling in command prompt:
pip install --force-reinstall translators=5.6.3 (or latest)
and fixing updated syntax

@SeanDunford
Copy link

@UlionTse can you explain a bit more as to why the following line:

os.environ['translators_default_region'] = 'xxx'

fixes the issue?

I'm using translators==5.7.6 on a mac and i was getting the unable to connect to the internet issue. The following link: https://geolocation.onetrust.com/cookieconsentpub/v1/geo/location does not load in any browser from my mac. Not using any non-default networking firewall/proxy on my machine.

@IveMalfunctioned Please upgrade version to 5.6.0 Do this os.environ['translators_default_region'] = 'xxx' before import translators, and then we'll skip the previous question.

@UlionTse
Copy link
Owner

@SeanDunford

Hello, bro.
The essence of this function is to show the location of the translation service used by the user, because different regions, even if the domain name is the same, the service provider may have different services. Second, to differentiate services in China from those in other countries, because Google and Microsoft offer additional services in China.

Based on that, can you load this https://httpbin.org/ip?

@UlionTse
Copy link
Owner

UlionTse commented Sep 27, 2023

@UlionTse can you explain a bit more as to why the following line:

os.environ['translators_default_region'] = 'xxx'

fixes the issue?

I'm using translators==5.7.6 on a mac and i was getting the unable to connect to the internet issue. The following link: https://geolocation.onetrust.com/cookieconsentpub/v1/geo/location does not load in any browser from my mac. Not using any non-default networking firewall/proxy on my machine.

@IveMalfunctioned Please upgrade version to 5.6.0 Do this os.environ['translators_default_region'] = 'xxx' before import translators, and then we'll skip the previous question.

@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.

@SeanDunford
Copy link

@UlionTse can you explain a bit more as to why the following line:

os.environ['translators_default_region'] = 'xxx'

fixes the issue?

I'm using translators==5.7.6 on a mac and i was getting the unable to connect to the internet issue. The following link: https://geolocation.onetrust.com/cookieconsentpub/v1/geo/location does not load in any browser from my mac. Not using any non-default networking firewall/proxy on my machine.

@IveMalfunctioned Please upgrade version to 5.6.0 Do this os.environ['translators_default_region'] = 'xxx' before import translators, and then we'll skip the previous question.

@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.

@UlionTse
Copy link
Owner

UlionTse commented Oct 7, 2023

@SeanDunford Bro, please pip install --upgrade translators==5.8.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants