leannmak / DisconfPythonAPI

A simple way to connect to Disconf-Web api.
2 stars 3 forks source link

disconf api的问题 #1

Open jinyuchen724 opened 6 years ago

jinyuchen724 commented 6 years ago

我在调用api的时候按照这个方式去调用报了以下错误,能帮忙看看什么原因吗? dapi.web_config_download_148.get()

send: 'GET /api/web/config/download/148 HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 38\r\nConnection: close\r\nUser-Agent: DisconfAPI\r\nHost: 172.16.8.42:8081\r\nCookie: JSESSIONID=E61127ECE3081895B88D4A24A3D6B2C5\r\nContent-Type: multipart/form-data; boundary=e57d53f8244f44429f12c38350e72d6f\r\n\r\n' send: <poster.encode.multipart_yielder instance at 0x186ee18> sendIng an iterable reply: 'HTTP/1.1 200 OK\r\n' header: Date: Tue, 19 Jun 2018 03:33:50 GMT header: Content-Type: application/octet-stream;charset=UTF-8 header: Content-Length: 15 header: Connection: close header: Server: Apache-Coyote/1.1 header: Set-Cookie: DISCONF=e308698d-1c4f-4917-9a66-42e63134743a; Domain=disconf.com; Expires=Wed, 19-Jun-2019 03:33:50 GMT; Path=/ header: Content-Disposition: attachment; filename=autoconfig.properties Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.7/site-packages/DisconfPythonAPI/dapi.py", line 184, in func return self.proxy_api(method=method, *params) File "/usr/lib64/python2.7/site-packages/DisconfPythonAPI/dapi.py", line 152, in ret return func(self, args, params) File "/usr/lib64/python2.7/site-packages/DisconfPythonAPI/dapi.py", line 159, in wrapper return self.url_request(method=method, params) File "/usr/lib64/python2.7/site-packages/DisconfPythonAPI/dapi.py", line 190, in url_request api=self.__api, method=method, **params) File "/usr/lib64/python2.7/site-packages/DisconfPythonAPI/dapi.py", line 139, in url_request content = json.loads(opener.read()) File "/usr/lib64/python2.7/json/init.py", line 338, in loads return _default_decoder.decode(s) File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib64/python2.7/json/decoder.py", line 384, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded

leannmak commented 6 years ago

Though I haven't got into such case so far, it seems that the response data from the disconf raw api might not be always strictly in json format. Now I've fix this bug and just try it again.

jinyuchen724 commented 6 years ago

hi leannmak , thank you for your response,i use the new code and no error return,i saw you add try,except to filtration error,but i still can't download file form disconf。

the information like this:

send: u'GET /api/web/config/list?envId=1&version=1_0_0_0&appId=2& HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 430\r\nConnection: close\r\nUser-Agent: DisconfAPI\r\nHost: 172.16.8.42:8081\r\nCookie: JSESSIONID=72817685A01D6EDFC1D32C2E5759283E\r\nContent-Type: multipart/form-data; boundary=ffbd42efdc7943d5bf1146354a282ca2\r\n\r\n' send: <poster.encode.multipart_yielder instance at 0x16db6c8> sendIng an iterable reply: 'HTTP/1.1 200 OK\r\n' header: Date: Wed, 20 Jun 2018 04:01:21 GMT header: Content-Type: application/json;charset=UTF-8 header: Transfer-Encoding: chunked header: Connection: close header: Server: Apache-Coyote/1.1 header: Set-Cookie: DISCONF=eef6d07f-bbf1-45c8-b7a2-f1f2f8d50fb2; Domain=disconf.com; Expires=Thu, 20-Jun-2019 04:01:21 GMT; Path=/ send: 'GET /api/web/config/download/148 HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 38\r\nConnection: close\r\nUser-Agent: DisconfAPI\r\nHost: 172.16.8.42:8081\r\nCookie: JSESSIONID=72817685A01D6EDFC1D32C2E5759283E\r\nContent-Type: multipart/form-data; boundary=0f734741649448448ca63f1e620bab66\r\n\r\n' send: <poster.encode.multipart_yielder instance at 0x16db6c8> sendIng an iterable reply: 'HTTP/1.1 200 OK\r\n' header: Date: Wed, 20 Jun 2018 04:01:21 GMT header: Content-Type: application/octet-stream;charset=UTF-8 header: Content-Length: 15 header: Connection: close header: Server: Apache-Coyote/1.1 header: Set-Cookie: DISCONF=bd29b695-2632-479f-900f-fd6c5c65dd27; Domain=disconf.com; Expires=Thu, 20-Jun-2019 04:01:21 GMT; Path=/ header: Content-Disposition: attachment; filename=autoconfig.properties

[root@hz01-dev-ops-cjy-01 /home/DisconfPythonAPI]

find / -name autoconfig.properties

and i can't find the properties file

leannmak commented 6 years ago

hi jinyuchen,

When using this python api, it may not really download a file to your local dir, but returns the content of the file instead. If you want to catch the content, pls do like this:

>>> file = dapi.web_config_download_154.get()
send: 'GET /api/web/config/download/154 HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 38\r\nConnection: close\r\nUser-Agent: DisconfAPI\r\nHost: 192.168.182.135\r\nCookie: JSESSIONID=81837948C1E5A257A86D893B013E199C\r\nContent-Type: multipart/form-data; boundary=b114b577f7c9450d984f0fdca334fb58\r\n\r\n'
send: <poster.encode.multipart_yielder instance at 0x7fe46d5ebcf8>
sendIng an iterable
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Wed, 20 Jun 2018 05:35:18 GMT
header: Content-Type: application/octet-stream;charset=UTF-8
header: Content-Length: 11
header: Connection: close
header: Server: Apache-Coyote/1.1
header: Set-Cookie: DISCONF=f9b8bdcc-72fe-4b84-bd42-470ba3d1aed7; Domain=localhost; Expires=Thu, 20-Jun-2019 05:35:18 GMT; Path=/
header: Content-Disposition: attachment; filename=lala.properties
>>> file
'hello world'

Only when using the browser to access the disconf api, you can straightly obtain a file as follow:

default

jinyuchen724 commented 6 years ago

hi leannmak , thank you very much,I can get the content of the file already, i will try other method to download the file with python。

thank you!!!