首页 \ 问答 \ Google App Engine:ImportError:没有名为appengine.ext的模块(Google App Engine: ImportError: No module named appengine.ext)

Google App Engine:ImportError:没有名为appengine.ext的模块(Google App Engine: ImportError: No module named appengine.ext)

我正在尝试为使用数据存储的GAE程序编写测试。 遵循Google的文档 ,我发现我应该将我的SDK的路径添加到我的PYTHONPATH中。 我这样做使用:

import sys
sys.path.remove('/usr/local/lib/python2.7/dist-packages')    # Has a 'google' module, which I want to be sure isn't interfering.
sys.path.insert(1,'/home/olly/google-cloud-sdk/platform/google_appengine')
sys.path.insert(1, '/home/olly/google-cloud-sdk/platform/google_appengine/lib/yaml/lib')

然后当文件运行时:

Traceback (most recent call last):
 File "myapp_tests.py", line 20, in <module>
    from google.appengine.ext import ndb
ImportError: No module named appengine.ext

我已经在上面的位置安装了SDK,并查看/home/olly/google-cloud-sdk/platform/google_appengine/我发现了google文件夹,里面有__init__.py ,以及appengine 。 基本上,文件夹结构看起来不错,他们都被正确命名并具有__init__.py文件。

在交互式控制台中,运行上面的命令后,我发现我可以运行:

import google

没问题,但是当我尝试

import google.appengine
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named appengine

我的理解是,在目录中使用__init__.py()文件意味着它们可以像上面那样导入。 我也做了一个sudo find / --name "google" ,唯一出现在我的PYTHONPATH中的是/usr/local/lib/python2.7/dist-packages ,我明确删除了,无论如何也将我剩下的路径插入前面。

我尝试使用GAE自己的方法:

import dev_appserver
dev_appserver.fix_sys_path()

它为sys.path添加了很多路径,但仍然无法让它工作。

我还发现,当我将'/home/olly/Servers/google_appengine/google'到我的路径中时,我可以运行:

import appengine.ext

但运行:

from appengine.ext import ndb

原因:

Traceback (most recent call last):
  File "booking_function_tests.py", line 16, in <module>
     from appengine.ext import ndb
  File "/home/olly/Servers/google_appengine/google/appengine/ext/ndb/__init__.py", line 7, in <module>
     from tasklets import *
  File "/home/olly/Servers/google_appengine/google/appengine/ext/ndb/tasklets.py", line 69, in <module>
     from .google_imports import apiproxy_stub_map
  File "/home/olly/Servers/google_appengine/google/appengine/ext/ndb/google_imports.py"    , line 11, in <module>
     from google3.storage.onestore.v3 import entity_pb
ImportError: No module named google3.storage.onestore.v3

我错过了一些非常明显的东西吗 我该如何导入导入ndb?

编辑:我正在运行最新的SDK(1.9.34),但我在google_imports.py中有以下代码:

try:
  from google.appengine.datastore import entity_pb
  normal_environment = True
except ImportError:
  try:
    from google3.storage.onestore.v3 import entity_pb
    normal_environment = False
  except ImportError:
    # If we are running locally but outside the context of App Engine.
    try:
      set_appengine_imports()
      from google.appengine.datastore import entity_pb
      normal_environment = True
    except ImportError:
      raise ImportError('Unable to find the App Engine SDK. '
                        'Did you remember to set the "GAE" environment '
                        'variable to be the path to the App Engine SDK?')

此外, google.__path__给了我'/usr/local/lib/python2.7/dist-packages'路径,我认为我之前删除了它。 以下是我如何删除它的摘录:

import sys
sys.path.insert(1, '/home/olly/Servers/google_appengine')
sys.path.insert(1, '/home/olly/Servers/google_appengine/lib/yaml/lib')
sys.path.remove('/usr/local/lib/python2.7/dist-packages')

import google
print google.__path__
print sys.path


['/usr/local/lib/python2.7/dist-packages/google']
['/home/olly/Servers/google_appengine/myapp', '/home/olly/Servers/google_appengine/lib/yaml/lib', '/home/olly/Servers/google_appengine/google', '/home/olly/Servers/google_appengine', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']

所以我的sys.path被更新了,但是import google似乎仍然是从不存在的路径导入的,这可能是我的问题的关键。 我需要重新加载路径吗?


I am trying to write a test for my GAE programme which uses the datastore. Following Google's Documentation, I see that I should be adding the path to my SDK into my PYTHONPATH. I did this using:

import sys
sys.path.remove('/usr/local/lib/python2.7/dist-packages')    # Has a 'google' module, which I want to be sure isn't interfering.
sys.path.insert(1,'/home/olly/google-cloud-sdk/platform/google_appengine')
sys.path.insert(1, '/home/olly/google-cloud-sdk/platform/google_appengine/lib/yaml/lib')

Then when the file is run:

Traceback (most recent call last):
 File "myapp_tests.py", line 20, in <module>
    from google.appengine.ext import ndb
ImportError: No module named appengine.ext

I have installed the SDK in the location above, and looking in /home/olly/google-cloud-sdk/platform/google_appengine/ I found the google folder, which has an __init__.py in it, along with appengine. Basically, the folder structure looks good to me, with them all being named correctly and having __init__.py files.

In an interactive console, after running the commands above, I found that I could run:

import google

no problem, but when I tried

import google.appengine
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named appengine

It was my understanding that having the __init__.py() files in the directories meant that they could be imported as above. I also did a sudo find / --name "google", and the only thing that showed up that is also in my PYTHONPATH was the /usr/local/lib/python2.7/dist-packages, which I explicitly removed, and also inserted the rest of my paths in front of anyway.

I tried using GAE's own method of:

import dev_appserver
dev_appserver.fix_sys_path()

which added a whole lot of paths to sys.path, but still didn't help me make it work.

I also found that when I add '/home/olly/Servers/google_appengine/google' to my paths, I can run:

import appengine.ext

but running:

from appengine.ext import ndb

causes:

Traceback (most recent call last):
  File "booking_function_tests.py", line 16, in <module>
     from appengine.ext import ndb
  File "/home/olly/Servers/google_appengine/google/appengine/ext/ndb/__init__.py", line 7, in <module>
     from tasklets import *
  File "/home/olly/Servers/google_appengine/google/appengine/ext/ndb/tasklets.py", line 69, in <module>
     from .google_imports import apiproxy_stub_map
  File "/home/olly/Servers/google_appengine/google/appengine/ext/ndb/google_imports.py"    , line 11, in <module>
     from google3.storage.onestore.v3 import entity_pb
ImportError: No module named google3.storage.onestore.v3

Am I missing something really obvious? How should I go about importing ndb?

EDIT: I'm running the latest SDK (1.9.34), but I have the following code in my google_imports.py:

try:
  from google.appengine.datastore import entity_pb
  normal_environment = True
except ImportError:
  try:
    from google3.storage.onestore.v3 import entity_pb
    normal_environment = False
  except ImportError:
    # If we are running locally but outside the context of App Engine.
    try:
      set_appengine_imports()
      from google.appengine.datastore import entity_pb
      normal_environment = True
    except ImportError:
      raise ImportError('Unable to find the App Engine SDK. '
                        'Did you remember to set the "GAE" environment '
                        'variable to be the path to the App Engine SDK?')

Also, google.__path__ gives me the '/usr/local/lib/python2.7/dist-packages' path which I thought I removed earlier. Here is an excerpt of how I'm removing it:

import sys
sys.path.insert(1, '/home/olly/Servers/google_appengine')
sys.path.insert(1, '/home/olly/Servers/google_appengine/lib/yaml/lib')
sys.path.remove('/usr/local/lib/python2.7/dist-packages')

import google
print google.__path__
print sys.path


['/usr/local/lib/python2.7/dist-packages/google']
['/home/olly/Servers/google_appengine/myapp', '/home/olly/Servers/google_appengine/lib/yaml/lib', '/home/olly/Servers/google_appengine/google', '/home/olly/Servers/google_appengine', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']

So my sys.path is updated, but import google seems to still be importing from the no-longer-there path, which would be the crux of my problem I guess. Do I need to reload the path or something?


原文:https://stackoverflow.com/questions/36022960
更新时间:2023-10-23 11:10

最满意答案

有很多可能的方法,但你自己做(它不在客户端)。

最简单的方法是:

  1. 注册客人/客人等已知信息,并通过SIP消息询问账户
  2. 创建http api,在启动jssip之前从javascript中使用它。

但是,既然你要提供任何凭据,我恐怕无法处理DDoS攻击或黑客攻击。


There are alot of possible approach, but you have do it yourself(it not in client).

Simplest ways are :

  1. register with known info like guest/guest and ask account via sip message
  2. create http api, use it from javascript before start jssip.

However since you are gooing to give ANYONE credentials, i am afraid no way deals with DDoS attack or hackers.

相关问答

更多
  • 在现代版本中你应该这样做 ldconfig 安装星号后。 如果将它安装在/ usr / local / path中,那么在此之前还应该将/ usr / local / lib /放入/etc/ld.so.conf.d/asterisk。 您可以使用find实用程序获取有关安装星号二进制文件的信息 find / -name asterisk In modern version you should do ldconfig After install of asterisk. If you in ...
  • 您的星号服务配置是什么? 它在数据库上运行吗? 您是否使用任何第三方计费软件和星号? 你在运行什么操作系统? 它是什么版本的星号? 绝对有办法做你想要完成的事情。 你看过'asterisk-java'库了吗? http://www.asterisk-java.org/development/tutorial.html What is the configuration of your asterisk service? Is it running on a database? Are you using a ...
  • 星号不是PROXY,它是pbx。 对于代理服务器(加载超过1k个电话或CPS超过80个),请使用kamailio。 您已启用核心转储并编译带调试标志的星号以进行调试。 你也可以考虑改变pjsip为chan_sip或反过来。 https://wiki.asterisk.org/wiki/display/AST/Getting+a+Backtrace Asterisk is not PROXY, it is pbx. For proxy(load over 1k calls or CPS over 80) pl ...
  • Asterisk插件在Openfire 3.10下不起作用。 使用最新的Openfire 3.9。*版本。 你可以在这里下载: Windows(安装程序) http://www.igniterealtime.org/downloads/download-landing.jsp?file=openfire/openfire_3_9_3.exe Debian http://www.igniterealtime.org/downloads/download-landing.jsp?file=openfire/op ...
  • 不再支持AsteriskGUI。 用户freepbx.org gui。 如果您需要AsteriskGUI(较旧的不受支持的版本),您需要在javascript调试中成为大师。 除了js问题,也可能是防火墙或/etc/asterisk/manager.conf文件的问题。 AsteriskGUI is not supported anymore. User freepbx.org gui. If you need AsteriskGUI(older unsupported version), you need ...
  • 正如@arheops指出的那样,编译取决于操作系统的版本和星号本身的版本。 以下内容在带有星号v14的Debian 9中运行 假设您在/ usr / src / asterisk中有源代码。 所以,首先要做的事情。 您必须下载依赖项: # apt-get update # apt-get install autoconf # cd /usr/src/asterisk/contrib/scripts # ./install_prereq install 然后,配置步骤: # cd /usr/asterisk ...
  • 这样的设置太复杂,不能让初学者保持稳定。 更好的选择(更安全)使用openvpn.org隧道而不使用TLS。 1)Freepbx只是用于简化控制星号的web。 我不建议将freepbx用于公共系统(如果是防火墙,则可以内部使用)。 您还需要在安装中添加fail2ban。 3) http://www.asteriskdocs.org/,http://cdn.oreilly.com/books/9780596510480.pdf 。 但是我担心你需要一些真实的经验才能按照你的要求工作。 4)虚拟机上的Dahdi ...
  • 是的,您可以通过ami收集活动(请参阅ami活动)。 https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+AMI+Events 你也可以将queue_log做成mysql http://www.voip-info.org/wiki/view/Asterisk+queue_log+on+MySQL Yes, you can collect events via ami(see ami events). https://wiki.asterisk.org ...
  • 免责声明:我不知道关于FileMaker的第一件事。 但是,如果它像任何其他编程语言一样(根据我所知,我不确定那是真的)那么让我们看看我们如何使用其他编程语言完成这一任务的选项...... 如果您只想要调用的结果,CDR(呼叫详细记录),您可以配置Asterisk在cdr_custom.conf输出自定义CDR(如果您生成了示例配置,请查看它) 这是cdr_custom.conf的一个例子: [mappings] Simple.csv => ${CSV_QUOTE(${EPOCH})},${CSV_QUOT ...
  • 有很多可能的方法,但你自己做(它不在客户端)。 最简单的方法是: 注册客人/客人等已知信息,并通过SIP消息询问账户 创建http api,在启动jssip之前从javascript中使用它。 但是,既然你要提供任何凭据,我恐怕无法处理DDoS攻击或黑客攻击。 There are alot of possible approach, but you have do it yourself(it not in client). Simplest ways are : register with known i ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。