cgi.FieldStorage() not work for python requests.post but work for requests.get

程淼 crazytomcheng at gmail.com
Fri May 5 06:04:10 EDT 2017


在 2017年5月5日星期五 UTC+8下午6:02:04,程淼写道:
> here is the client use get 
> ------------------------------------------------------------------
> import json 
> import requests 
> 
> url = "http://abc.com:11/ip" 
> auth = {"ip":["10.100.1.1","10.100.1.2"], 
>          "time": "20170504133025" 
>         } 
> 
> try: 
>     req = requests.get(url,params=auth)     
> 
> except requests.exceptions.ConnectionError,e: 
>     print e 
> else: 
>     print req 
>     print req.headers 
>     print req.text 
> ------------------------------------------------------------------
> 
> but not work for post 
> ------------------------------------------------------------------
> import json 
> import requests 
> 
> url = "http://abc.com:11/ip" 
> auth = {"ip":["10.100.1.1","10.100.1.2"], 
>          "time": "20170504133025" 
>         } 
> 
> try: 
>     headers = {'Content-Type': 'application/json'} 
>     req = requests.post(url=url,data=json.dumps(auth),headers=headers) 
> 
> except requests.exceptions.ConnectionError,e: 
>     print e 
> else: 
>     print req 
>     print req.headers 
>     print req.text 
> ------------------------------------------------------------------
> arguments always get FieldStorage(None, None, []) 
> 
> 
> and i use other post way, it works. 
> ------------------------------------------------------------------
> <!DOCTYPE html> 
> <html><head><title>login</title></head> 
> <body> 
> <form action="http://abc.com:11/ip/" method="post"> 
> <input type="text" name="ip"/> 
> <input type="text" name="time"/> 
> <input type="submit"/> 
> </form> 
> </body> 
> </html> 
> ------------------------------------------------------------------
> 
> is this any problem requests.post(python) with cgi.FieldStorage ? 
> 
> 
> Thanks

Server : Apache/2.4.10 (Debian)



More information about the Python-list mailing list