Python 当我将代码放入服务器时,why translator.detect(..).lang给了我异常,而它在本地主机上运行良好

Python 当我将代码放入服务器时,why translator.detect(..).lang给了我异常,而它在本地主机上运行良好,python,google-translate,Python,Google Translate,这是我的代码部分,只有当我在服务器上使用代码时才会出现异常,而当我在本地主机上使用代码时,它不会出现异常。有人能解释为什么它的行为不同以及如何解决它吗?我真的不明白为什么。我的服务器使用linux,本地主机使用windows if len(title) > 4: try: time.sleep(3) detection = translator.detect(title[:40]).lang # print('detection' ,

这是我的代码部分,只有当我在服务器上使用代码时才会出现异常,而当我在本地主机上使用代码时,它不会出现异常。有人能解释为什么它的行为不同以及如何解决它吗?我真的不明白为什么。我的服务器使用linux,本地主机使用windows

if len(title) > 4:
    try:
        time.sleep(3)
        detection = translator.detect(title[:40]).lang
        # print('detection' , detection)
        if detection != "en":
            print("language detected not english")
            return -4
    except:
        print('inside except checksum')
        return -4
title[:40]是一个有效字符串,下面是我的输出

Page 0...
inside except checksum
inside except checksum
inside except checksum
inside except checksum
inside except checksum
inside except checksum
inside except checksum
inside except checksum
inside except checksum
inside except checksum
inside except checksum
inside except checksum
inside except checksum
inside except checksum
outdated
inside except checksum
outdated
Page 1...
inside except checksum
inside except checksum
.
.
.

很难说是什么引发了异常,因为您的代码破坏了证据。将
exception
更改为
exception as e
,并将
e
放入
print
调用中。事实上,如果不知道确切的异常,就很难找到根本原因。按照BoarGules的建议,让我们知道您发现了什么异常。很难说是什么引发了异常,因为您的代码破坏了证据。将
exception
更改为
exception as e
,并将
e
放入
print
调用中。事实上,如果不知道确切的异常,就很难找到根本原因。遵循博阿古利斯的建议,让我们知道您发现了什么异常情况。