Python Mechanize + GAEpython代码 [英] Python Mechanize + GAEpython code

查看:123
本文介绍了Python Mechanize + GAEpython代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道以前关于机械化+ Google App Engine的问题,

Mechanize和Google App Engine

还有一些代码这里,我无法在应用引擎上工作,抛出

 文件D:\data\eclipse-php\testpy4\src\mechanize\_http.py,第43行,在socket._fileobject(fake socket,close = True)
文件C:\程序文件(x86)\Google\google_appengine\google\appengine\dist\socket.py,第42行,位于_fileobject
fp.fileno = lambda:None
Attrib uteError:'str'对象没有属性'fileno'
INFO 2009-12-14 09:37:50,405 dev_appserver.py:3178]GET / HTTP / 1.1500 -

是否有人愿意分享他们的工作机制+ appengine代码?

解决方案

我已经解决了这个问题,只需更改第43行,
中的mechanize._http.py的代码:

<$ p
socket._fileobject(fake socket,close = True)
除了TypeError:
#python< = 2.4
create_readline_wrapper = socket._fileobject
else:
def create_readline_wrapper(fh):
返回socket._fileobject(fh,close = True)

$ b

到:

 尝试:
#固定开始 - - 固定为gae
类x:
传递

#x应该是一个对象,而不是一个字符串
#这是关键
socket ._fileobject(x,close = True)
#fixed ended
ex cept TypeError:
#python< = 2.4
create_readline_wrapper = socket._fileobject
else:
def create_readline_wrapper(fh):
返回socket._fileobject(fh,close = True)


I am aware of previous questions regarding mechanize + Google App Engine, What pure Python library should I use to scrape a website? and Mechanize and Google App Engine.

Also there is some code here, which I cannot get to work on app engine, throwing

File "D:\data\eclipse-php\testpy4\src\mechanize\_http.py", line 43, in socket._fileobject("fake socket", close=True)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\dist\socket.py", line 42, in _fileobject
fp.fileno = lambda: None
AttributeError: ’str’ object has no attribute ‘fileno’
INFO 2009-12-14 09:37:50,405 dev_appserver.py:3178] "GET / HTTP/1.1″ 500 -

Is anybody willing to share their working mechanize + appengine code?

解决方案

I have solved this problem, just change the code of mechanize._http.py, about line 43, from:

try:
    socket._fileobject("fake socket", close=True)
except TypeError:
    # python <= 2.4
    create_readline_wrapper = socket._fileobject
else:
    def create_readline_wrapper(fh):
        return socket._fileobject(fh, close=True)

to:

try:
    # fixed start -- fixed for gae
    class x:
        pass

    # the x should be an object, not a string,
    # This is the key
    socket._fileobject(x, close=True)
    # fixed ended
except TypeError:
    # python <= 2.4
    create_readline_wrapper = socket._fileobject
else:
    def create_readline_wrapper(fh):
        return socket._fileobject(fh, close=True)

这篇关于Python Mechanize + GAEpython代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆