python
  • azure
  • microsoft-cognitive
  • 2017-06-19 5 views 0 likes 
    0

    Ich versuche jetzt den folgenden Code aus azur Notebook in python3 ImportanforderungenAnruf microsoft kognitive Leistungen Übersetzer mit Python

    # Getting the key from tab Keys on Azure portal 
    key = "xxxxxxxxxxx" 
    
    
    url4authentication = 'https://api.cognitive.microsoft.com/sts/v1.0/issueToken' 
    headers4authentication = {'Ocp-Apim-Subscription-Key': key} 
    resp4authentication = requests.post(url4authentication, headers=headers4authentication) 
    token = resp4authentication.text 
    
    print(token) 
    text="hello there how are you" 
    come = "en" 
    to = "es" 
    url4translate = 'https://api.microsofttranslator.com/v2/http.svc/Translate' 
    from xml.etree import ElementTree 
    response = requests.get('https://api.microsofttranslator.com/v2/http.svc', params = param) 
    print(response) 
    

    und ich erhalte die folgenden Fehler:

    OSError         Traceback (most recent call last) 
    /home/nbuser/anaconda3_23/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, **response_kw) 
        587    if is_new_proxy_conn: 
    --> 588     self._prepare_proxy(conn) 
        589 
    
    /home/nbuser/anaconda3_23/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py in _prepare_proxy(self, conn) 
        800 
    --> 801   conn.connect() 
        802 
    
    /home/nbuser/anaconda3_23/lib/python3.4/site-packages/requests/packages/urllib3/connection.py in connect(self) 
        290    # self._tunnel_host below. 
    --> 291    self._tunnel() 
        292    # Mark this connection as not reusable 
    
    /home/nbuser/anaconda3_23/lib/python3.4/http/client.py in _tunnel(self) 
        856    raise OSError("Tunnel connection failed: %d %s" % (code, 
    --> 857                message.strip())) 
        858   while True: 
    
    OSError: Tunnel connection failed: 403 Forbidden 
    

    Antwort

    0

    nur als Referenz, ich schlagen Sie zuerst vor, Sie können versuchen, auf meine Antwort für den anderen ähnlichen SO Thread Response from Microsoft Translate API in Python zu verweisen, um Ihr Problem zu lösen. Wenn Sie mehr Bedenken haben, wenden Sie sich bitte an mich.

    +0

    Vielen Dank für Ihre Antwort. Jetzt habe ich einen anderen Fehler: OSError Traceback (letzter Anruf zuletzt) ​​ Irgendeine Idee, was es sein kann – hinda

    +0

    @hinda Bitte aktualisieren Sie den Inhalt über den Code mit 'OSError' in Ihrem Beitrag und was in Details passiert. –

    Verwandte Themen