[英]How to pass results of urllib2.urlopen to a function
WHen I run this I get the following error - TypeError: coercing to Unicode: need string or buffer, NoneType found 当我运行这个时,我得到以下错误 - TypeError:强制转换为Unicode:需要字符串或缓冲区,找到NoneType
Can someone please tell me how I can pass the results of function getURL() to function romid()? 有人可以告诉我如何将函数getURL()的结果传递给函数romid()?
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import serial, time, os, decimal, csv, urllib2, socket
import xml.etree.cElementTree as ET
from xml.etree.cElementTree import parse
romidList = []
id = '{http://www.embeddeddatasystems.com/schema/owserver}ROMId'
owd= '{http://www.embeddeddatasystems.com/schema/owserver}owd_DS18B20'
def getURL():
f = urllib2.urlopen(''.join(['http://', '169.254.1.2', '/details.xml']))
#add the next line
return f
def romid():
f = getURL()
for x in parse(f).findall(owd):
romID = x.find(id)
romID = romID.text
if romID not in romidList:
romidList.append(romID)
print romidList
romid()
嗯...你考虑过在你的getURL
函数中使用return
语句吗?
您找到NoneType,因为您没有在getURL()函数中返回任何内容,您只是声明变量f,而不是返回它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.