Discuss / Python / 只能是sina吗?

只能是sina吗?

Topic source

L0standfound

#1 Created at ... [Delete] [Delete and Lock User]

这个sina主页有什么特别的么? 为什么我把sina.com.cn换成douban.com就会报错呢? 报错信息如下: Traceback (most recent call last): File "untitled.py", line 27, in <module> header, html = data.split(b'\r\n\r\n', 1) ValueError: need more than 1 value to unpack

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

把data打印出来看

叫小小兽

#3 Created at ... [Delete] [Delete and Lock User]

我之前也跟你一样,原因是你把send里面的字符串写错了,好好检查一下是不是少了空格或者字母错了

歆歆物语

#4 Created at ... [Delete] [Delete and Lock User]

d=s.recv(1024)为什么会出现 Traceback (most recent call last): File "D:\PythonPractic\TCP.py", line 9, in <module> d=s.recv(1024) error: [Errno 10054]

我换成www.douban.com 运行结果是这样的: HTTP/1.1 403 Forbidden Server: dae Date: Sat, 26 Dec 2015 13:25:16 GMT Content-Type: text/html Content-Length: 160 Connection: close

之前试的新浪和百度都是正常的,第一句都是 HTTP/1.1 200 OK 而豆瓣是Forbodden, 不知道为什么。

廖雪峰

#6 Created at ... [Delete] [Delete and Lock User]

因为有很多服务器检测到不是浏览器发的请求就拒掉了


  • 1

Reply