A question about unicode() function



Hi,all
I encountered a problem when using unicode() function to fetch a
webpage, I don't know why this happenned.
My codes and error messages are:


Code:
#!/usr/bin/python
#Filename: test.py
#Modified: 2006-12-31

import cPickle as p
import urllib
import htmllib
import re
import sys

def funUrlFetch(url):
lambda url:urllib.urlopen(url).read()

objUrl = raw_input('Enter the Url:')
content = funUrlFetch(objUrl)
content = unicode(content,"gbk")
print content
content.close()


error message:

C:\WINDOWS\system32\cmd.exe /c python test.py
Enter the Url:http://www.msn.com
Traceback (most recent call last):
File "test.py", line 16, in ?
content = unicode(content,"gbk")
TypeError: coercing to Unicode: need string or buffer, NoneType found
shell returned 1
Hit any key to close this window...

Any suggestions would be appreciated!

Thanks!

.



Relevant Pages

  • Re: A question about unicode() function
    ... I just removed the unicodemethod from my codes. ... I had an wrong understanding of unicode and ascii. ... Paul Watson wrote: ... My codes and error messages are: ...
    (comp.lang.python)
  • Re: A question about unicode() function
    ... JTree wrote: ... I changed the codes and now it works fine. ... My codes and error messages are: ... TypeError: coercing to Unicode: need string or buffer, ...
    (comp.lang.python)
  • Re: [FAQ] What does @ (at-sign) do?
    ... Dunlop of comp.lang.php make plain: ... How about the Unicode name 'COMMERCIAL AT'? ... > suppresses error messages. ...
    (comp.lang.php)
  • Re: A question about unicode() function
    ... I changed the codes and now it works fine. ... I encountered a problem when using unicodefunction to fetch a ... My codes and error messages are: ... TypeError: coercing to Unicode: need string or buffer, ...
    (comp.lang.python)
  • Re: A question about unicode() function
    ... My codes and error messages are: ... #Filename: test.py ... Once you fix the lambda, as Felipe described, there's another issue here. ... You are telling the unicode function that the string you're passing it is ...
    (comp.lang.python)