我使用python,这是我的代码
myUser = 'username'
myServer = 'http://api.url.net', "{\"orga\":\"monorga\",\"coupon\":\"moncoupon\"}"
myPass = 'pass'
authString = base64.encodestring('%s:%s' % (myUser, myPass))
headers = {'Authorization':"Basic %s" % authString}
req = urllib2.Request(myServer, None, headers)
openedUrl = urllib2.urlopen(req)
url = url.strip()
AttributeError: 'tuple' object has no attribute 'strip'
请帮帮我
当你写
url = 'https://api.url.net', "{\"orga\":\"monorga\",\"coupon\":\"moncoupon\"}"
的时候,基本上你只需要创建一个tuple
的两个元素('https://api.url.net'
和"{\"orga\":\"monorga\",\"coupon\":\"moncoupon\"}"
),并将这个元组的引用分配给url
变量。这是因为,在python中,并不总是需要编写元组的括号:a = 1, 2
。因此,
url
现在是元组。另外,元组没有strip
方法,因此不能调用url.strip
。要在
url
上调用strip
,必须首先将其转换为字符串。相关问题 更多 >
编程相关推荐