注册 登录
编程论坛 Python论坛

针对 TypeError: expected string or buffer,新手求教,求解释;谢谢。

pretty975 发布于 2011-05-25 10:51, 14856 次点击
大家好。。我遇到的是程序在本地测试没有出现问题,在python上面直接编程运行也没问题。。
但是我的程序上传到google上就出现问题。

程序大概如下:

import urllib2,re,time
import cookielib
from urllib2 import urlopen, Request

cookieFile = 'cookies.dat'
testURL = 'http://???.com'   ####某个网址,带登陆后的信息
cJar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cJar))
urllib2.install_opener(opener)
r = Request(testURL)
h = urlopen(r)
a = h.info().getheader('Set-Cookie')
################### a应该是字符串,大概是 alxn=cdb791ff; domain=.???.com; path=/; expires=Fri, 24-Jun-2011 02:39:56 GMT, mt=5UKXMHc;domain=. path=/
b=('mt=([^;]*)')   ##############  我只需要a,里面的“mt”那一段字符串
mt = b.search(a).group(1)    ##############  用前面的mt= b.search(a).group(1)和用mt = b.search(str(a)).group(1)在本地测试,都不报错,但是传到google上就报错,且在此行报  TypeError: expected string or buffe 的错误
print mt
。。。。。。。。。。
在本地测试这个程序,没有问题


1 回复
#2
pretty9752011-05-25 12:25
。。帮忙看下啦,要是哪个朋友也遇到  TypeError: expected string or buffer
也发出来,共享下。
1