bob_the_bob
bob_the_bob

Reputation: 355

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

Can someone please tell me how I can pass the results of function getURL() to function 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()

Upvotes: 0

Views: 110

Answers (2)

Python Spoils You
Python Spoils You

Reputation: 394

You are getting NoneType found because your not returning anything in your getURL() function, you are just declaring the variable f, not returning it

Upvotes: 0

Mihai Zamfir
Mihai Zamfir

Reputation: 2166

well...have you considered using the return statement in your getURL function?

Upvotes: 2

Related Questions