这个是什么错误:ValueError: unsupported format character 'H' (0x48) at index 6

cndeer 2012-03-02 05:47:59
这是代码:

# -*- coding:cp936 -*-
import asyncore, socket
class http_client(asyncore.dispatcher): #定义了一个http_client类
def __init__(self, host, path):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, 80))
self.buffer = 'GET % HTTP/1.0 \r\n\r\n' % path
def handle_connect(self): #链接调用接口
pass
def handle_close(): #接口关闭方法
self.close()
def handle_read(self):
print self.recv(8192)
def writable(self):
return (len(self.buffer)>0)
def handle_write(self):
sent = self.send(self.buffer)
self.buffer = self.buffer[sent:]
if __name__ == '__main__':
c = http_client(' snaps.php.net', '/')
asyncore.loop()
print 'program exit'



这是错误:
---------- Python ----------
Traceback (most recent call last):
File "1.2.2.py", line 21, in <module>
c = http_client(' snaps.php.net', '/')
File "1.2.2.py", line 8, in __init__
self.buffer = 'GET % HTTP/1.0 \r\n\r\n' % path
ValueError: unsupported format character 'H' (0x48) at index 6

输出完成 (耗时 0 秒) - 正常终止
...全文
1145 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
angel_su 2012-03-02
  • 打赏
  • 举报
回复
报错很正常嘛,字符格式化用法不对, 貌似你应该'GET %s HTTP/1.0 \r\n\r\n' ...

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧