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

程淼 crazytomcheng at gmail.com
Sun May 7 22:20:54 EDT 2017


在 2017年5月5日星期五 UTC+8下午6:04:26,程淼写道:
> 在 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)

hi guys

I found the problem.

If python requests.post run on windows server,it would have problem.
I ran it(requests.post) on linux server,it worked.

Thank you.






More information about the Python-list mailing list