Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload file #1

Open
Tearlachpellerin1 opened this issue May 6, 2022 · 3 comments
Open

Upload file #1

Tearlachpellerin1 opened this issue May 6, 2022 · 3 comments

Comments

@Tearlachpellerin1
Copy link

I have a problem to generate a API command to Upload files.
Do you an Idea?

@dominikholler
Copy link
Owner

Nice to see that this code gets some attention.
Can you share the command or the line of code which does not behave like expected?

@Tearlachpellerin1
Copy link
Author

I have attach a function upload in the Class Client
The API description is:

POST /api/v1/upload/:path

client.py

def upload(self, path):
    print(path)
    return self._post(f'/upload/{path}')

test.py

import timeit
import pathlib
api = Client(
domain='http://127.0.0.1:2342',
username='xxxxx',
password='xxxxx',
debug=False
)

iterations = 10

file_path =pathlib.Path('/my/path/').as_uri()

print(file_path)

answare = api.upload(file_path)
print(answare)

Error

I get following Error:
JSONDecodeError: [Errno Expecting value]

JSONDecodeError: [Errno Expecting value]

@Tearlachpellerin1
Copy link
Author

The full Error Message:


JSONDecodeError Traceback (most recent call last)
~/.local/lib/python3.8/site-packages/requests/models.py in json(self, **kwargs)
909 try:
--> 910 return complexjson.loads(self.text, **kwargs)
911 except JSONDecodeError as e:

/usr/lib/python3/dist-packages/simplejson/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, use_decimal, **kw)
517 and not use_decimal and not kw):
--> 518 return _default_decoder.decode(s)
519 if cls is None:

/usr/lib/python3/dist-packages/simplejson/decoder.py in decode(self, s, _w, _PY3)
369 s = str(s, self.encoding)
--> 370 obj, end = self.raw_decode(s)
371 end = _w(s, end).end()

/usr/lib/python3/dist-packages/simplejson/decoder.py in raw_decode(self, s, idx, _w, _PY3)
399 idx += 3
--> 400 return self.scan_once(s, idx=_w(s, idx).end())

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError Traceback (most recent call last)
/tmp/ipykernel_1351231/522715474.py in
18
19
---> 20 uuu = api.upload('/my/path/')
21 print(uuu)

/tmp/ipykernel_1351231/2304628905.py in upload(self, path)
89 def upload(self, path):
90 print(path)
---> 91 return self._post(f'/upload/{path}')
92
93 @_inspect_response

/tmp/ipykernel_1351231/2304628905.py in wrapper(*args, **kwargs)
14 _check_for_error(response)
15 response.raise_for_status()
---> 16 return response.json()
17 return wrapper
18

~/.local/lib/python3.8/site-packages/requests/models.py in json(self, **kwargs)
915 raise RequestsJSONDecodeError(e.message)
916 else:
--> 917 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
918
919 @Property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants