我想要达到的目标很简单。你知道吗
我想使用Flask创建一个通过API调用(特别是ParseServer)连接到远程服务器的web应用程序。 我使用第三方库来实现这一点,当我在独立脚本中运行代码时,一切都能完美地工作。但是当我将代码添加到烧瓶中时,我突然无法通过服务器进行身份验证
Or to be more precise I get an 'unauthorized' error when executing an API call.
在我看来,在Flask中,APi库使用的注册方法不被记住。你知道吗
我尝试了很多方法,将注册和初始化代码放在Flask中的不同位置,但都没有成功。你知道吗
我在Library的Github中问了一个类似的问题,没有任何帮助。你知道吗
所以我想我有两个问题可以帮我解决这个问题
1)我应该在哪里放置注册方法并从该库导入文件? &
2)我能做些什么来明确问题,例如确切地知道问题出在哪里?你知道吗
这里有一些代码
烧瓶代码在这里
@app.route('/parseinsert')
def run_parse_db_insert():
"""The method for testing implementation and design of the Parse Db
"""
pc = ParseCommunication()
print(pc.get_all_names_rating_table())
return 'done'
ParseCommunication是我处理Parse的类。如果我从该脚本运行ParseCommunication,使用与上述main部分相同的代码,一切都会正常工作。你知道吗
我和德夫一起运行烧瓶程序_应用服务器.py来自谷歌应用引擎。你知道吗
我的文件夹结构
/parseTest
/aplication
views.py
app.yaml
run.py
我的运行.py代码
import os
import sys
sys.path.insert(1, os.path.join(os.path.abspath('.'), 'lib'))
sys.path.insert(1, os.path.join(os.path.abspath('.'), 'application'))
import aplication
让我知道我还能提供什么帮助。你知道吗
先谢谢你
编辑:
请求的堆栈跟踪。 它主要与图书馆有关(据我所知?)你知道吗
ERROR 2016-09-28 06:45:50,271 app.py:1587] Exception on /parseinsert [GET]
Traceback (most recent call last):
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/theshade/Devel/ParseBabynames/parseTest/aplication/views.py", line 34, in run_parse_db_insert
name = pc.get_user('testuser1')
File "/home/theshade/Devel/ParseBabynames/parseTest/aplication/parseCommunication.py", line 260, in get_user
return User.Query.get(username=uname)
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/query.py", line 58, in get
return self.filter(**kw).get()
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/query.py", line 150, in get
results = self._fetch()
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/query.py", line 117, in _fetch
return self._manager._fetch(**options)
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/query.py", line 41, in _fetch
return [klass(**it) for it in klass.GET(uri, **kw).get('results')]
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/connection.py", line 108, in GET
return cls.execute(uri, 'GET', **kw)
File "/home/theshade/Devel/ParseBabynames/parseTest/lib/parse_rest/connection.py", line 102, in execute
raise exc(e.read())
ResourceRequestLoginRequired: {"error":"unauthorized"}
Parse需要键和env变量。检查这行:
API_ROOT = os.environ.get('PARSE_API_ROOT') or 'https://api.parse.com/1'
您的错误在第102行:
https://github.com/milesrichardson/ParsePy/blob/master/parse_rest/connection.py
在解析之前,您需要注册:
相关问题 更多 >
编程相关推荐