python 什么是http异步请求

http请求为耗时IO操作,如果同步阻塞的话,进程会等待请求完成。
异步的话,进程会发出http请求(请求以后不需要cpu),然后跳转到别的任务,直到http请求完成,再调回来继续处理得到的http回应。
最经典的例子就是烧水,同步阻塞就是你一直蹲在炉子旁边等待水烧开,而异步是把水壶放在炉子上,等水开了以后茶壶会叫,这时候你听到声音就会回来处理开水~

❷ python 怎么实现http服务器

简而言之,它是在物理服务器上搭建的一个网络连接服务器(networking server),永久地等待客户端发送请求。当服务器收到请求之后,它会生成响应并将 其返回至客户端。客户端与服务器之间的通信,是以HTTP协议进行的。客户端可以是浏览器,也可以是任何支持HTTP协议的软件
那么,网络服务器的简单实现形式会是怎样的呢?下面是我对此的理解。示例代码使用Python语言实现,不过即使你不懂Python语言,你应该也可以从代码和下面的 解释中理解相关的概念:
?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

import socket

HOST, PORT = '', 8888

listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind((HOST, PORT))
listen_socket.listen(1)
print 'Serving HTTP on port %s ...' % POR

❸ 装完python之后出现的http://localhost:7464/是用来做什么的

您好,你好像应该在命令行中执行以下命令:pydoc -p 7464

参考:http://en.wikibooks.org/wiki/How_to_Think_Like_a_Computer_Scientist:_Learning_with_Python_2nd_Edition/Moles_and_files

❹ 如何用Python写一个http post请求

python发送post和get请求
get请求:
使用get方式时,请求数据直接放在url中。
方法一、
importurllib
importurllib2
url="<ahref="http://192.168.81.16/cgi-bin/python_test/test.py?ServiceCode=aaaa""target="_blank">http://192.168.81.16/cgi-bin/python_test/test.py?ServiceCode=aaaa"</a>
req=urllib2.Request(url)
printreq
res_data=urllib2.urlopen(req)
res=res_data.read()
printres
方法二、
importhttplib
url="<ahref="http://192.168.81.16/cgi-bin/python_test/test.py?ServiceCode=aaaa""target="_blank">http://192.168.81.16/cgi-bin/python_test/test.py?ServiceCode=aaaa"</a>
conn=httplib.HTTPConnection("192.168.81.16")
conn.request(method="GET",url=url)
response=conn.getresponse()
res=response.read()
printres
post请求:
使用post方式时,数据放在data或者body中,不能放在url中,放在url中将被忽略。
方法一、
importurllib
importurllib2
test_data={'ServiceCode':'aaaa','b':'bbbbb'}
test_data_urlencode=urllib.urlencode(test_data)
requrl="<ahref="http://192.168.81.16/cgi-bin/python_test/test.py""target="_blank">http://192.168.81.16/cgi-bin/python_test/test.py"</a>
req=urllib2.Request(url=requrl,data=test_data_urlencode)
printreq
res_data=urllib2.urlopen(req)
res=res_data.read()
printres

方法二、
importurllib
importhttplib
test_data={'ServiceCode':'aaaa','b':'bbbbb'}
test_data_urlencode=urllib.urlencode(test_data)
requrl="<ahref="http://192.168.81.16/cgi-bin/python_test/test.py""target="_blank">http://192.168.81.16/cgi-bin/python_test/test.py"</a>
headerdata={"Host":"192.168.81.16"}
conn=httplib.HTTPConnection("192.168.81.16")
conn.request(method="POST",url=requrl,body=test_data_urlencode,headers=headerdata)
response=conn.getresponse()
res=response.read()
printres

❺ python 怎么导入httplib

例子

#!/usr/bin/envpython
#-*-coding:utf-8-*-
importhttplib
importurllib


defsendhttp():
data=urllib.urlencode({'@number':12524,'@type':'issue','@action':'show'})
headers={"Content-type":"application/x-www-form-urlencoded",
"Accept":"text/plain"}
conn=httplib.HTTPConnection('bugs.python.org')
conn.request('POST','/',data,headers)
httpres=conn.getresponse()
printhttpres.status
printhttpres.reason
printhttpres.read()


if__name__=='__main__':
sendhttp()

❻ python3没有httplib了吗

1、有,python3把httplib改了名字,对应的库是http.client

2、网址是:

https://docs.python.org/3.4/library/http.client.html

https://docs.python.org/2/library/httplib.html

❼ python3么有httplib了吗

python3把httplib改了名字,对应的专库是属http.client
https://docs.python.org/3.4/library/http.client.html
https://docs.python.org/2/library/httplib.html

❽ 为啥我的python 没有http.server

在Windows下使用是有这个包的。 不过很奇怪,我在14.04版本上python2是没有,python3有。

这个不太对。因版为http包应该是一个标权准的包。其中有server模块更是常用。

可能问题就是在python2和python3上。在python2你可以用BaseHttpServer, SimpleHTTPServer, httplib等模块完成同样的功能。

❾ 如何使用python立即发送http请求参数

1 首先安装requests这个模块,方法是 输入pip install requests。当然你要装好pip这个包管理器。

2 然后
import requests
url = " " # 这里是你的url
your_param = {'Refer':"sina_index"} # 这里是你要发送的请求参数!, 它在url后边加上 ??Refer=sina_index这样子的东东

result = requests.get(url, param = your_param) # 发送请求,如果url是http://s.weibo.com/weibo/s 那么 这句话的的效果就是 http://s.weibo.com/weibo/s?Refer=sina_index
result_final = result.text #这样你就获取到了你发送的这个URL + 参数 之后的结果

全部手打的,点赞呗。