數據如何發送到服務器?非ASCII字符在調用URL時Python中出現語法錯誤
例如,我有獲取MAC地址,所以我想發送到服務器(例如http://211.21.24.43:8080/data?mac=00-0C-F1-56-98-AD)
我在網上找到這段代碼:
from urllib2 import Request, urlopen
from binascii import b2a_base64
def b64open(url, postdata):
req = Request(url, b2a_base64(postdata), headers={'Content-Transfer-Encoding': 'base64'})
return urlopen(req)
conn = b64open("http://211.21.24.43:8080/data","mac=00-0C-F1-56-98-AD")
但是當我運行它,我得到:
File "send2.py", line 8
SyntaxError: Non-ASCII character '\xc3' in file send2.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
任何人都可以幫助我發送數據到服務器?
在此先感謝
1.發佈問題時,請使用頁面右側的格式指南。 2.請用大寫字母開始句子和專有名詞,如「I」。 – 2010-04-07 10:27:08
你怎麼能問最糟糕的答案? – diegoaguilar 2014-03-10 14:42:32