Comments (10)
@kbairak can you help on this? any tip?
Thanks!
from transifex-python.
Hello @jjscarafia . Yes I can.
First of all it's not your fault. Secondly, it's kind-of not the fault of the SDK. It is mostly the fault of the API.
If you see here, the .data.attributes
field of the request is required, but none of its child fields are. So, this request payload will work:
POST {"data": {"type": "resource_translations_async_downloads",
"relationships": {"...": "..."},
"attributes": {}}}
but this will not:
POST {"data": {"type": "resource_translations_async_downloads",
"relationships": {"...": "..."}}}
This doesn't make much sense and it is a mistake on the part of the API. If none of the attributes are required, the attributes should also not be required.
The SDK tries to be smart about how to generate these payloads. So when you do
transifex_api.ResourceTranslationsAsyncDownload.download(resource=resource,
language=language)
It creates a payload like:
{"data": {"type": "...",
"relationships": {"resource": {"...": "..."},
"language": {"...": "..."}}}}
which is invalid, according to the API.
To get around this for now, you can add at least one of the attributes specified in the API docs using the default value:
transifex_api.ResourceTranslationsAsyncDownload.download(resource=resource,
language=language,
content_encoding="text")
which will create this payload:
{"data": {"type": "...",
"attributes": {"content_encoding": "text"},
"relationships": {"resource": {"...": "..."},
"language": {"...": "..."}}}}
which is valid.
I am sorry about this and I will make sure that:
- The API doesn't consider the
attributes
field to be required - The SDK Readme examples are useful
Thanks for bringing this to my attention.
from transifex-python.
Hey, good news! It works now. As I described, the fix was implemented on the API side, so no updates of this library is needed.
from transifex-python.
Thanks you a lot @kbairak
Quick answer, great explanation and a fix :)
I'm getting a different error now, I'm not sure if it's related or not.
I'm using python 3.7
resource: '<Resource: o:adhoc:p:ingadhoc-odoo-argentina-ce-13-0:r:l10n_ar_afipws_fe>'
language: '<Language: l:es>'
Error:
JSONDecodeError Traceback (most recent call last)
in
----> 1 url = transifex_api.ResourceTranslationsAsyncDownload.download(resource=resource, language=language)
~/.local/lib/python3.7/site-packages/transifex/api/init.py in download(cls, interval, *args, **kwargs)
29 return download.redirect
30 time.sleep(interval)
---> 31 download.reload()
32
33
~/.local/lib/python3.7/site-packages/transifex/api/jsonapi/resources.py in reload(self, include)
260 params = {'include': ','.join(include)}
261 url = self.links.get('self', self.get_item_url())
--> 262 response_body = self.API.request('get', url, params=params)
263 if (isinstance(response_body, requests.Response) and
264 response_body.status_code == 303):
~/.local/lib/python3.7/site-packages/transifex/api/jsonapi/apis.py in request(self, method, url, bulk, headers, data, files, allow_redirects, **kwargs)
216 raise exc
217 try:
--> 218 return response.json()
219 except JSONDecodeError:
220 # Most likely empty response when deleting
/usr/local/lib/python3.7/site-packages/requests/models.py in json(self, **kwargs)
895 # used.
896 pass
--> 897 return complexjson.loads(self.text, **kwargs)
898
899 @Property
~/.local/lib/python3.7/site-packages/simplejson/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, use_decimal, **kw)
523 parse_constant is None and object_pairs_hook is None
524 and not use_decimal and not kw):
--> 525 return _default_decoder.decode(s)
526 if cls is None:
527 cls = JSONDecoder
~/.local/lib/python3.7/site-packages/simplejson/decoder.py in decode(self, s, _w, _PY3)
368 if _PY3 and isinstance(s, bytes):
369 s = str(s, self.encoding)
--> 370 obj, end = self.raw_decode(s)
371 end = _w(s, end).end()
372 if end != len(s):
~/.local/lib/python3.7/site-packages/simplejson/decoder.py in raw_decode(self, s, idx, _w, _PY3)
398 elif ord0 == 0xef and s[idx:idx + 3] == '\xef\xbb\xbf':
399 idx += 3
--> 400 return self.scan_once(s, idx=_w(s, idx).end())
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
from transifex-python.
Hmm, this part:
local/lib/python3.7/site-packages/transifex/api/jsonapi/apis.py in request(self, method, url, bulk, headers, data, files, allow_redirects, **kwargs)
216 raise exc
217 try:
--> 218 return response.json()
219 except JSONDecodeError:
220 # Most likely empty response when deleting
is supposed to catch this specific error. I remember that not all Python versions are consistent about their definition of the JSONDecodeError
. I thought I had taken care of this with some code in api/jsonapi/compat.py
. Obviously I hadn't run sufficient tests with Python 3.7. This will require some digging into but I am confident I will come up with a solution.
from transifex-python.
Thanks! we'll try with different python versions and let you know
from transifex-python.
Hey, @jjscarafia.
I have created this PR #64. Its description explains why you are getting this error. You can wait for the PR to be merged and a new minor release to take place. Or, in the meantime, you can try removing simplejson
from your environment.
from transifex-python.
Another update @jjscarafia:
The newest release, 1.0.1 has the aforementioned fix. You should be ok now, even if you don't uninstall simplejson.
from transifex-python.
Working now! thanks a lot @kbairak !
from transifex-python.
Thank you for checking this out. I am using the SDK a lot myself to set up test data in order to fix things in Transifex, but I am very excited to help with real-world use.
from transifex-python.
Related Issues (15)
- Python 3.12 support HOT 5
- CDS 404 Client Error HOT 1
- Error when translation None is django template
- Not working with django model field verbose_name=lazyt("Title") HOT 4
- Transifex native not working in combination with Django 3.x due to deprecated access HOT 1
- transifex_api.ResourceTranslationsAsyncDownload.download fails with missing attributes error HOT 3
- Unable to pull from today HOT 2
- Support custom CDS handlers HOT 1
- [Django] Can't translate models.TextChoices enum values HOT 15
- Can't disable HTML escape when using lazy translation HOT 2
- Tests is installed as package HOT 2
- Is the OpenAPI spec available over HTTPS?
- APIv3: Bulk actions for /resource_translations_async_downloads GET and POST?
- Transifex doesn't work with Django 4.0 or later. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from transifex-python.