开发者

Error, Retrieving a web page with data in Python 3

I have written a very basic Python 3 function to retrieve a web page with some data but I am getting an error message:

import urllib.parse
开发者_JS百科import urllib.request

def fetch_web (url, par1,par2="",par3=""):

    values  = {"s":"stor","l":"SVEENG"}
    data = urllib.parse.urlencode(values)
    req = urllib.request.Request(url,data)

    response = urllib.request.urlopen(req)

    page = response.read()

url = "http://wwww.ord.se"
fetch_web(url,"stor")

When executing this program I am getting following error message:

TypeError: POST data should be bytes or an iterable of bytes. It cannot be str.

Any ideas about the misstake?


You should learn about Bytes vs Characters in Python 3.

And them use byte strings like: b'...' for data you post to a website.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜