0

我对以下代码有错误。当我尝试运行它时,我得到一个

Exception has occurred: AttributeError
type object 'QStringEncoder' has no attribute 'Utf8'

我最初在导入这个库时遇到了问题,但是当我实施不同的导入方法时,它们得到了修复。其他库工作正常,只是这个引发了这个错误。代码包含在下面。

import http.client
from PyQt6 import QtCore


# Encode
string = "Hello World"
fromUtf16 = QtCore.QStringEncoder(QtCore.QStringEncoder.Utf8)
encodedString = fromUtf16(string)

# request logic
conn = http.client.HTTPSConnection("google-translate1.p.rapidapi.com")

# string as
encodedString = "q=Hello%2C%20world!&target=es&source=en"
#                         target lang ^         ^ base lang

headers = {  # all static fields
    "content-type": "application/x-www-form-urlencoded",
    "accept-encoding": "application/gzip",
    "x-rapidapi-key": "4679425f88mshcb1cacb0c2357d8p1e02e8jsn4e69292eb0dc",
    "x-rapidapi-host": "google-translate1.p.rapidapi.com",
}

conn.request("POST", "/language/translate/v2", encodedString, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
4

0 回答 0