简体   繁体   English

通过RESTful API通过Python安装ArangoDB Foxx请求导致“未经授权”错误

[英]Installing ArangoDB Foxx via RESTful API via Python requests results in 'unauthorized' error

We use ArangoDB and Python using the requests module to use Arango's HTTP API. 我们使用ArangoDB和Python使用请求模块来使用Arango的HTTP API。 I'm having authorisation problems deploying a Foxx app programically via the HTTP API which we'd like to do as part of our automated testing process. 我在通过HTTP API以编程方式部署Foxx应用程序时遇到授权问题,这是我们在自动化测试过程中要做的。 The only program example I can find of uploading an app appears to use obsolete routes. 我可以找到的唯一一个上载应用程序的程序示例似乎使用了过时的路由。 I can upload the zip: 我可以上传压缩文件:

http://mydev:8529/_db/mydb/_api/upload

I get back: 我回来了:

{"filename": "uploads/tmp-13-718410"}

...and the file is there. ...文件在那里。 But then trying this with the post data {"zipFile": "uploads/tmp-13-718410"}: 但是,然后尝试使用发布数据{“ zipFile”:“ uploads / tmp-13-718410”}:

http://mydev:8529/_db/mydb/_admin/aardvark/foxxes/zip?mount=%2Fmy-mount-point

I get back {"error": "unauthorized"}. 我回来了{“ error”:“ unauthorized”}。 I realise that it's telling me what's wrong but I'm using basic auth both for the _system db and mydb (the username/password is the same for both). 我意识到这是在告诉我什么地方出了问题,但是我正在对_system db和mydb使用基本身份验证(两者的用户名/密码相同)。 I can create/drop databases via the HTTP API no problem but I can't seem to use the aardvark module. 我可以通过HTTP API创建/删除数据库,没问题,但似乎无法使用aardvark模块。

I am using 2.6.8. 我正在使用2.6.8。

My code in python is: 我在python中的代码是:

import requests

self._requests = requests.Session()
self._requests.auth = ('user', 'password')

# create the database
r = self._requests.post('http://mydev:8529/_api/database', json={'name': 'mydb', 'users': [{'username': 'user' 'passwd': 'password'}]})

...all searches, inserts, etc. via the HTTP API all work. ...所有通过HTTP API进行的搜索,插入等操作均有效。

Then when later installing a Foxx app via the HTTP API: 然后,当以后通过HTTP API安装Foxx应用程序时:

r = self._requests.post('http://mydev:8529/_db/mydb/_api/upload', data=data) # succeeds
filename = r.json()['filename']

data = {'zipFile': filename}
r = self._requests.put(
    r'http://mydev:8529/_db/mydb/_admin/aardvark/foxxes/zip?mount=%2Fmy-mount-point',
    json=data
)

I get back {"error": "unauthorized"}. 我回来了{“ error”:“ unauthorized”}。

The app works fine when I install the app using the UI or simply copying the files to the correct location and bouncing the database. 当我使用UI安装应用程序或将文件复制到正确的位置并启动数据库时,该应用程序运行良好。

Do I need to separately send credentials to use the aardvark route in a way I'm not doing it here? 我是否需要以我不在此使用的方式单独发送凭据以使用aardvark路由? Am I missing a step? 我错过了一步吗?

I think when all URLs in the /_admin/aardvark realm require separate (cookie-based) authentication, as they belong to the (graphical) admin interface. 我认为/_admin/aardvark领域中的所有URL都需要单独的(基于cookie的)身份验证,因为它们属于(图形)管理界面。 Calling such URL in the browser will probably bring up the login screen, regardless of whether HTTP basic authentication data is sent with the request. 无论是否随请求一起发送HTTP基本认证数据,在浏览器中调用此类URL都可能会显示登录屏幕。

To install a Foxx application via the REST API, I think the better API endpoint is HTTP PUT /_admin/foxx/install . 要通过REST API安装Foxx应用程序,我认为更好的API端点是HTTP PUT /_admin/foxx/install

It will require a JSON body to be sent, with attributes named mount and appInfo . 它将需要发送带有名为mountappInfo属性的JSON正文。 mount needs to contain the mountpoint (needs to start with a forward slash). mount需要包含mount点(需要以正斜杠开头)。 appInfo is the application to be mounted. appInfo是要挂载的应用程序。 It can contain the filename as previously returned by the server from the call to /_api/upload , eg 它可以包含服务器先前从/_api/upload调用返回的文件名,例如

{ 
    "appInfo" : "uploads/tmp-30573-2010894858", 
    "mount" : "/my-mount-point" 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM