如何部署这个“Python +斜纹+机械化”组合到“Google App Engine”? [英] How to deploy this "Python+twill+mechanize" combination to "Google App Engine"?

查看:90
本文介绍了如何部署这个“Python +斜纹+机械化”组合到“Google App Engine”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将登录名和密码从 Python 脚本传递到 eBay 登录页面。稍后我希望这个脚本从 Google App Engine 运行



我建议您使用机械化 。不幸的是,它对我来说不起作用:






  IDLE 1.2.4 
>>>> import re
>>>进口机械化
>>> br = mechanize.Browser()
>>> br.open(https://signin.ebay.com)

追溯(最近的最后一次呼叫):
文件< pyshell#3>,第1行, <模块>
br.open(https://signin.ebay.com)
文件build\bdist.win32\egg\mechanize\_mechanize.py,第203行,打开
return self._mech_open(url,data,timeout = timeout)
文件build\bdist.win32\egg\mechanize\_mechanize.py,第255行,在_mech_open
raise response
httperror_seek_wrapper:HTTP错误403:robots.txt禁止请求
>>>






此前我试图使用 Python 斜纹 - 在 一个支持者建议 ,我下载最新版本的机械化然后执行以下步骤:


  1. 在我的电脑上找到以下文件夹: C:\将其名称更改为 _mechanize_dist_backup,然后将其名称更改为 _mechanize_dist_backup,然后单击确定,然后单击确定。 (完整路径应为 C:\Python25\Lib\site-packages\twill\other_packages\twill\other_packages\_mechanize_dist_backup


  2. 复制机械化文件夹(位于 mechanize-0.2.2 中 - r已从 机械化官方网站下载并解压缩 / a>),并将其粘贴到 C:\Python25\Lib\site-packages\twill\other_packages (完整路径,因此为 C: \Python25\Lib\site-packages\twill\other_packages\mechanisation


  3. 将其名称更改为 _mechanize_dist (完整路径为 C:\Python25\Lib\site-packages\twill\other_packages_mechanize_dist


  4. _mechanize_dist_backup 复制 ClientForm 文件,并将其粘贴到 _mechanize_dist ,我发现有两个名为 ClientForm 的文件:一个是一个python文件,另一个是一个编译的python文件 - 我复制并粘贴了这两个文件)。


执行所有这些步骤后,我尝试从 Python 中的斜纹 shell登录到我的 eBay 帐户,工作!我甚至可以以相同的方式登录到我的雅虎邮箱,并检查我的邮件!



但现在我有一个困境:我不知道如何将脚本部署到 Google App Engine



早期 App Engine 中使用第三方库,那么我已经建议一个可以运行的google-app-en / strong>项目,当我部署它时,我只需要包含我的应用程序 - 例如,在斜纹的情况下,我只需要将斜纹文件夹复制到我的应用程序的文件夹并部署它。



但是现在,我不仅将此斜纹文件夹作为第三方库进行包含,还可以在 C:\Python25 (在 C:\Python25\Lib\site-packages\twill\other_packages 中,我的应用文件夹 - 我有我的脚本( my_script .py文件) - 位于 E 磁盘。


有人可以在这里给我一些建议吗?

解决方案

对于GAE部署问题,@brilliant,看起来像你正在处理的代码都是纯python 2.5(唯一的真正的阻塞问题是,如果它不是 - 不允许二进制扩展,没有代码需要Python 2.6或更好的允许,这只是在这个时候GAE的方式)。 >

因此,在这种假设下,在App Engine上部署代码的唯一问题是将中的所有代码 NOT site-packages (当然,GAE的 dev_appserver.py 绝对不会部署nada,zilch),而是在您的GAE项目目录建议所有.py文件的递归zip,只有 - 删除所有的.pyc文件,特别是在您的 zip -r 之前; - )。



总而言之,这只是几个相应shell命令的问题: cp -R then zip -r (可能更难于非unixy shell,但是,嘿,甚至在Windows上,您可以使用cygwin的bash进行...在任何情况下,这几乎不是开发问题; - )。


I've been trying to pass my login and password from Python script to the eBay sign-in page. Later I want this script to be run from "Google App Engine"

I was suggested to use "mechanize". Unfortunately, it didn't work for me:


IDLE 1.2.4      
>>> import re
>>> import mechanize
>>> br = mechanize.Browser()
>>> br.open("https://signin.ebay.com")

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    br.open("https://signin.ebay.com")
  File "build\bdist.win32\egg\mechanize\_mechanize.py", line 203, in open
    return self._mech_open(url, data, timeout=timeout)
  File "build\bdist.win32\egg\mechanize\_mechanize.py", line 255, in _mech_open
    raise response
httperror_seek_wrapper: HTTP Error 403: request disallowed by robots.txt
>>> 


Earlier I was trying to use Python and twill - it didn't work either until one supporter suggested that I download the latest version of mechanize and then perform the following steps:

  1. Locate the following folder on my computer: "C:\Python25\Lib\site-packages\twill\other_packages\_mechanize_dist"

  2. Change its name to "_mechanize_dist_backup" (the full path, thus, should be "C:\Python25\Lib\site-packages\twill\other_packages\_mechanize_dist_backup")

  3. Copy the "mechanize" folder (which is located in "mechanize-0.2.2" - the folder that I had downloaded and unzipped from the "mechanize" official site) and paste it in "C:\Python25\Lib\site-packages\twill\other_packages" (the full path, thus, being "C:\Python25\Lib\site-packages\twill\other_packages\mechanize")

  4. Change its name to "_mechanize_dist" (the full path being "C:\Python25\Lib\site-packages\twill\other_packages_mechanize_dist")

  5. Copy "ClientForm" file from "_mechanize_dist_backup" and paste it in "_mechanize_dist" (in fact, I found there two files named "ClientForm": one is a python file, another one is a compiled python file - I copied and pasted both of them).

After I had performed all these steps, I tried to log in to my eBay account from the twill shell in Python and it worked!!! I could even log in to my Yahoo mail box in the same way and check my mails!

But now I have a dilemma: I don't know how I could deploy my script to "Google App Engine".

Earlier I had been advised that if I want to use third-party libraries in App Engine projects, I simply have to include them with my application when I deploy it - in case with twill, for example, I just need to copy the twill folder into my application's folder and deploy it.

But now not only do I have this twill folder as a third-party library to be included, but also all these changes performed in "C:\Python25" (in "C:\Python25\Lib\site-packages\twill\other_packages", to be precise) while my application folder - the one in which I have my script ("my_script.py" file) - is located on "E" disk.

Can anybody, please, give me some suggestions here?

解决方案

As for GAE deployment issue, @brilliant, looks like the code you're dealing is all pure python 2.5 (the only really blocking issue would be if it isn't -- no binary extensions allowed, no code requiring Python 2.6 or better allowed, and that's just the way it is on GAE at this time).

So, under this assumption, the only issue w/deploying the code on App Engine is having all the code, NOT in site-packages (from which of course GAE's dev_appserver.py deploys absolutely nothing, nada, zilch), but rather in your GAE project's directory (I suggest a recursive zip of all the .py files, only -- remove all the .pyc files, in particular, before you zip -r it;-).

All in all, it's just a question of a couple of appropriate shell commands: cp -R then zip -r (probably harder on non-unixy shells, but, hey, even on Windows you can do it with bash from cygwin... in any case, it's hardly a "development" issue, per se;-).

这篇关于如何部署这个“Python +斜纹+机械化”组合到“Google App Engine”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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