Extension and HTTP401 errors

19 views
Skip to first unread message

oLcaYsaH

unread,
Sep 29, 2011, 2:05:02 PM9/29/11
to Pattern
Hello All,

I am new here and about Python, I am now in learning progress. When i
am doing examples i have errors that i couldn't solve.

Error1: from "downloads an image" example

from pattern.web import URL
>>> url = URL('http://www.clips.ua.ac.be/media/pattern_schema.gif')
>>> f = open('test'+extension(url.page), 'w') # save as test.gif

Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
f = open('test'+extension(url.page), 'w') # save as test.gif
NameError: name 'extension' is not defined

Error2 : from "pattern.graph" example

>>> from pattern.web import Yahoo, plaintext
>>> from pattern.en import Sentence, Chunk, parse
>>> from pattern.search import Pattern
>>> from pattern.graph import Graph, Node, Edge, export
>>>
>>> g = Graph()
>>> for i in range(5):
for r in Yahoo().search('"more important than"', start=i+1,
count=100):
s = plaintext(r.description.lower())
s = Sentence(parse(s))
p = Pattern.fromstring('NP (VP) more important than NP')
for m in p.search(s):
a = m.constituents(p[+0])[-1] # Left NP.
b = m.constituents(p[-1])[+0] # Right NP.
a = (isinstance(a, Chunk) and a.head or a).string
b = (isinstance(b, Chunk) and b.head or b).string
if a and b:
if a not in g:
g.add_node(a, radius=4, stroke=(0,0,0,0.8))
if b not in g:
g.add_node(b, radius=4, stroke=(0,0,0,0.8))
g.add_edge(g[a], g[b], stroke=(0,0,0,0.6))



Traceback (most recent call last):
File "<pyshell#22>", line 2, in <module>
for r in Yahoo().search('"more important than"', start=i+1,
count=100):
File "C:\Python27\lib\site-packages\pattern-2.1-py2.7.egg\pattern\web
\__init__.py", line 970, in search
raise HTTP401Authentication
HTTP401Authentication

Any though is really helps.

John DeBovis

unread,
Sep 29, 2011, 3:31:32 PM9/29/11
to Pattern
For you first question you did not import extension. I'm assuming you
copied this example:

>>> from pattern.web import URL, extension
>>> f = open('test' + extension(url.page), 'w') # save as test.gif
>>> f.write(url.download())
>>> f.close()

You could easily just do a 'from pattern.web import * ' to solve this.
or the way the example had it.

The answer to the second question seems to be simple. A 404 HTTP
response is page not found, a 401 is authentication issue. For more
info http://www.checkupdown.com/status/E401.html

Documentation says:
2 Yahoo.search(type=IMAGES) has a count of 1-35. The Yahoo API is a
paid service.

Tom De Smedt

unread,
Sep 29, 2011, 3:32:26 PM9/29/11
to Pattern
These are errors in the documentation. Thanks for noticing. I've
updated the docs.

In the image example, you should also import the extension() function:
from pattern.web import URL, extension

In the graph example, Yahoo is used. However, since a couple of months
Yahoo no longer offers a free query service (you get a 401 error
because you need a paid Yahoo BOSS account). I've rewritten the
example to use Bing, which is free.

Best,
Tom

I've updated the online documentation now.

oLcaYsaH

unread,
Sep 29, 2011, 4:24:13 PM9/29/11
to Pattern
Thank you Guys for comments.

They worked.

Thanks again,
Reply all
Reply to author
Forward
0 new messages