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

yipeiwu_com7年前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程序设计有所帮助。

相关文章

Python编程在flask中模拟进行Restful的CRUD操作

Python编程在flask中模拟进行Restful的CRUD操作

这篇文章中我们将通过对HelloWorld的message进行操作,介绍一下如何使用flask进行Restful的CRUD。 概要信息 事前准备:flask liumiaocn:f...

Python多线程编程(二):启动线程的两种方法

在Python中我们主要是通过thread和threading这两个模块来实现的,其中Python的threading模块是对thread做了一些包装的,可以更加方便的被使用,所以我们使...

python pandas 对时间序列文件处理的实例

如下所示: import pandas as pd from numpy import * import matplotlib.pylab as plt import copy d...

Pandas中resample方法详解

Pandas中的resample,重新采样,是对原样本重新处理的一个方法,是一个对常规时间序列数据重新采样和频率转换的便捷的方法。 方法的格式是: DataFrame.resampl...

Python线性拟合实现函数与用法示例

Python线性拟合实现函数与用法示例

本文实例讲述了Python线性拟合实现函数与用法。分享给大家供大家参考,具体如下: 1. 参考别人写的: #-*- coding:utf-8 -*- import math impo...