פייטון

avivfl2

New member
פייטון

בעיה עם מודול mechanize

זה מה שכתבתי

import mechanize


url="http://www.ynet.co.il"
br = mechanize.Browser()
br.addheaders = [('User-agent', 'Firefox')]
br.set_proxies({"http": "115.124.64.162:3128"})

x=br.open(url)

print x.read


וזה מה שקיבלתי


/usr/bin/python2.7 "/root/PycharmProjects/calc/web anonymous.py"
Traceback (most recent call last):
File "/root/PycharmProjects/calc/web anonymous.py", line 9, in <module>
x=br.open(url)
File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_mechanize.py", line 203, in open
return self._mech_open(url, data, timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_mechanize.py", line 230, in _mech_open
response = UserAgentBase.open(self, request, data)
File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_opener.py", line 193, in open
response = urlopen(self, req, data)
File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_urllib2_fork.py", line 344, in _open
'_open', req)
File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_urllib2_fork.py", line 332, in _call_chain
result = func(*args)
File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_urllib2_fork.py", line 1142, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_urllib2_fork.py", line 1118, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 101] Network is unreachable>

Process finished with exit code 1


אשמח לעזרה, תודה
 

BravoMan

Active member
לפי הודעת השגיאה שאתה מקבל הבעיה כלל אינה

במודול או בקוד שלך (שאגב עובד עצלי למעט הפרוקסי שכאמור אין לי), אלא בכך שהמחשב לא מחובר לרשת, או לפחות מזוהה כלא מחובר.

השורה הרוולנטית ביותר היא השורה האחרונה:

urllib2.URLError: <urlopen error [Errno 101] Network is unreachable>


האם דפדפנים עובדים לך עם הגדרות הפרוקסי האלה?
האם בדקת שכלים אחרים, למשל wget או curl מצליחים להגיע לאנשהו?
 

selalerer

New member
יכול להיות גם שהוא בילבל בפרמטרים ושלח...

...לשדה של הכתובת את הערך http במקום את ה-ip.
 

avivfl2

New member
היי

קודם כל אני עושה את זה תוך כדי חיבור הביתה מרוחק כך שאין סיכוי שאני לא מחובר לאינטרנט
עכשיו ניסיתי להוריד את ה proxy

import mechanize


url="http://www.ynet.co.il&quot;
br = mechanize.Browser()
br.addheaders = [('User-agent', 'Firefox')]
#br.set_proxies({"http": "115.124.64.162:3128"})

x=br.open(url)

print x.read


ואני מקבל


/usr/bin/python2.7 "/root/PycharmProjects/calc/web anonymous.py"
<bound method response_seek_wrapper.read of <response_seek_wrapper at 0x95b370c whose wrapped object = <closeable_response at 0x95df50c whose fp = <socket._fileobject object at 0x95ad92c>>>>

Process finished with exit code 0
 

mazory

New member
read זו פונקציה

נראה שהתוכנית הצליחה אבל אתה מדפיס את החתימה של הפונקציה במקום לקרוא לה.

נסה:

print x.read() zzzzz
 
למעלה