Umhumushi we-async googletrans wamukela i-proxy URL
Sebenzisa ingxabano eyodwa ye-proxy ku-async Translator ye-googletrans bese uvula i-HTTPX client ngomphathi wesimo we-async.
I-async Translator ye-googletrans iveza ingxabano eyodwa ye-proxy futhi iyidlulisela ku-HTTPX AsyncClient:
import asyncio
from googletrans import Translator
async def main():
async with Translator(proxy='http://proxy.example:8080') as translator:
translated = await translator.translate('Bonjour', dest='en')
print(translated.text)
asyncio.run(main())
Isimo se-async sivula i-HTTPX client eyisisekelo. Ukushaya i-translate ngaphandle kokuyilinda kungenye indlela ye-API futhi akwenzi lo msebenzi we-async.
I-proxy URL ingakhomba kumsindo ojwayelekile we-HTTP nakuba indawo yokugcina yokuhumusha isebenzisa i-HTTPS. Kuhlolo oluvunyelwe ngombhalo ongabucayi, uhlu lwe-proxy ye-HTTP lunikeza abazongenela indawo yokugcina yomphakathi. Uma kudingeka i-akhawunti ye-proxy, kusetshenziswa imininingwane yomsebenzisi efakwe ngendlela efanele yaleyo URL noma ukulungiselelwa kwe-proxy okusekelwa yi-HTTPX.
Izibonelo ezindala zazidlulisa amamephu e-proxies anezinto zangaphakathi ze-httpcore.SyncHTTPProxy. Lawa ancike kuma-interface amadala e-googletrans ne-httpcore. Ungawahlanganisi nalesi sakhi se-async somphakathi.
I-googletrans isebenzisa i-interface yewebhu ye-Google Translate; iyiphakethe nemodeli yokuqinisekisa ehlukile kune-Google Cloud Translation SDK esemthethweni. Qinisekisa ukuthi yiluphi iklayenti uhlelo olulungenisa ngempela ngaphambi kokusebenzisa ukulungiselelwa kwayo kwe-proxy.