2017-09-23 125 views
2

我的python版本是3.4,下面是錯誤信息。Python SyntaxError:無效的語法

Traceback (most recent call last): 
    File "test.py", line 1, in <module  
    from avs_client import AlexaVoiceServiceClient 
    File "/home/mstts/Documents/Amazon/alexa-voice-service-client/avs_client/__init__.py", line 1, in <module  
    from avs_client.avs_client.client import AlexaVoiceServiceClient 
    File "/home/mstts/Documents/Amazon/alexa-voice-service-client/avs_client/avs_client/client.py", line 5, in <module  
    from avs_client.avs_client import authentication, connection, device, ping 
    File "/home/mstts/Documents/Amazon/alexa-voice-service-client/avs_client/avs_client/connection.py", line 64 
    **authentication_headers, 
    ^
SyntaxError: invalid syntax 

下面是引發錯誤的代碼段。

headers = { 
     **authentication_headers, 
     'Content-Type': multipart_data.content_type 
    } 

非常感謝任何能夠讓我知道我做錯了什麼的人,以及爲什麼那會很棒!

+1

'authentication_headers'是一個字典嗎?那麼,什麼是錯誤的:'header = {'Content-Type':multipart_data.content_type}'和'headers.update(authentication_headers)'? – ozgur

+1

粘貼您的完整密碼 –

+0

@Ozgur Vatansever,這個改變很有效。但爲什麼**在這裏不起作用? –

回答

1

這個額外的字典文本的解包語法是在Python 3.5中引入的(請參閱PEP-448);在早期版本中,這是一個語法錯誤。如果不能升級,你將有兩個步驟來創建標題,例如:

headers = {'Content-Type': multipart_data.content_type} 
headers.update(**authentication_headers) 

通過Özgür的in the comments的建議。