python使用post提交数据到远程url的方法

yipeiwu_com6年前Python基础

本文实例讲述了python使用post提交数据到远程url的方法。分享给大家供大家参考。具体如下:

import sys, urllib2, urllib
zipcode = "S2S 1R8"
url = 'http://www.yoursiteweb.com/getForecast'
data = urllib.urlencode([('query', zipcode)])
req = urllib2.Request(url)
fd = urllib2.urlopen(req, data)
while 1:
  data = fd.read(1024)
  if not len(data):
    break
  sys.stdout.write(data)

希望本文所述对大家的Python程序设计有所帮助。

相关文章

对python3 Serial 串口助手的接收读取数据方法详解

其实网上已经有许多python语言书写的串口,但大部分都是python2写的,没有找到一个合适的python编写的串口助手,只能自己来写一个串口助手,由于我只需要串口能够接收读取数据就可...

Python3+PyInstall+Sciter解决报错缺少dll、html等文件问题

Python3+PyInstall+Sciter解决报错缺少dll、html等文件问题

1 调试过程 用Python3.6+Sciter+PyCharm写了一个py测试脚本helloworld.py,该脚本中只含有一条语句“import sciter”。在PyCharm中运...

pymongo为mongodb数据库添加索引的方法

本文实例讲述了pymongo为mongodb数据库添加索引的方法。分享给大家供大家参考。具体实现方法如下: from pymongo import ASCENDING, DESCEN...

python中的print()输出

1.普通的输出: print(str)#str是任意一个字符串,数字··· 2.格式化输出: print('1,2,%s,%d'%('asd',4)) 1,2,asd,4 与C语...

python给微信好友定时推送消息的示例

如下所示: from __future__ import unicode_literals from threading import Timer from wxpy import...