-1
我使用這個代碼:文字期快譯通
import urllib2
submit = urllib.urlencode(dict(sign.username='example'))
,但我得到這個錯誤:
SyntaxError: keyword can't be an expression
sign.username
是在我編碼URL參數,但Python不會讓我使用它,我該如何解決這個問題?
我使用這個代碼:文字期快譯通
import urllib2
submit = urllib.urlencode(dict(sign.username='example'))
,但我得到這個錯誤:
SyntaxError: keyword can't be an expression
sign.username
是在我編碼URL參數,但Python不會讓我使用它,我該如何解決這個問題?
要解決你的問題,使用字典(字典)字面括號{}
並圍繞重點單引號和值:
import urllib2
submit = urllib.urlencode({'sign.username':'example'})
使用字典文字格式 - 你或許應該無論如何做。
urllib.urlencode({'sign.username': 'example'})
爲什麼不'submit = urllib.urlencode({'sign.username':'example'})'? – brandizzi