Giter VIP home page Giter VIP logo

python-transifex's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

python-transifex's Issues

ValueError: No JSON object could be decoded

Executing pull_translations on project pitchupcom
Pulling translations for "pitchupcom" project, in "en_GB" source language
Traceback (most recent call last):
  File "manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/app/pitchup/campsite/management/commands/tx.py", line 80, in handle
    command_func(*args[1:], **options)
  File "/app/pitchup/campsite/management/commands/tx.py", line 164, in transifex_pull_translations
    project_slug=self.project_slug, source_language=self.source_language
  File "/app/lib/djangotransifex/api.py", line 157, in pull_translations
    resources = self.list_resources(project_slug)
  File "/usr/local/lib/python2.7/site-packages/transifex/api.py", line 106, in list_resources
    return json.loads(response.content)
  File "/usr/local/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Using it in django-transifex but error is in here.

the response.content is no longer json encoded

image

according to the response headers it's python pickle format

image

My guess is that the request headers which by default set to accept / and a user agent of python-requests cause their api to issue a different format in response.

image

Modify `.get_translation()` method to return data instead of writing to a file

It would be useful if .get_translation() return data instead of writing to file. In order to not to break backward compatibility it can return data if path_to_pofile argument is None. Something like that:

def get_translation(self, project_slug, resource_slug, language_code,
                    path_to_pofile=None):
    ...
    url = '%s/project/%s/resource/%s/translation/%s/' % (
        self._base_api_url, project_slug, resource_slug, language_code
    )
    output_path = path_to_pofile
    query = {
        'file': ''
    }
    response = requests.get(url, auth=self._auth, params=query)
    if response.status_code != requests.codes['OK']:
        raise TransifexAPIException(response)
    else:
        if path_to_file is not None:
            handle = open(output_path, 'w')
            for line in response.iter_content():
                handle.write(line)
            handle.close()
        else:
            return response.content

The purpose of changes in my case is to load a bunch of translated files then ask a user where to save them and then write them to that directory.

setup.py install_requires has requirements that are only needed at runtime

setup.py is reading the contents of requirements.txt and using that for the install_requires attribute. However, this has several problems:

  • install_requires should only be used for runtime deps. Its values are placed in the egg info and code that uses the package and pkg_resources won't run without those being installed. requirements.txt is used for constructing a buildtime or a recommended environment so the packageset it wants will be different.
  • install_requires is more abstract than requirements.txt. As explained to me on IRC:

[10:44:05] abadger1999: yes, setup.py requirements are abstract, they don't specify anything about where to get it from, it's jsut "I need a list of things that claim to be X, Y and Z", where requirements.txt is "I need X from pypi.python.org, Y from foo.example.com, Z from foo.com"

The recommendation from pip authors is that requirements.txt and setup.py should have two separate lists since they serve two different purposes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.