Django celery 4 - ValueError: invalid literal for int() with base 10 when start celery worker

青春壹個敷衍的年華 提交于 2020-04-10 08:09:08

问题


I have configured my celery.py as its documents but I put my celery broker url to AWS SQS but I cannot start it to work. When I run the celery worker, I get the ValueError as:


    File "/Users/abd/Desktop/proj-aws/lib/python3.6/site-packages/celery/bin/base.py", line 244, in __call__
      ret = self.run(*args, **kwargs)
    File "/Users/abd/Desktop/proj-aws/lib/python3.6/site-packages/celery/bin/worker.py", line 255, in run
      **kwargs)
    File "/Users/abd/Desktop/proj-aws/lib/python3.6/site-packages/celery/worker/worker.py", line 99, in __init__
      self.setup_instance(**self.prepare_args(**kwargs))
    File "/Users/abd/Desktop/proj-aws/lib/python3.6/site-packages/celery/worker/worker.py", line 120, in setup_instance
      self._conninfo = self.app.connection_for_read()
    File "/Users/abd/Desktop/proj-aws/lib/python3.6/site-packages/celery/app/base.py", line 752, in connection_for_read
      return self._connection(url or self.conf.broker_read_url, **kwargs)
    File "/Users/abd/Desktop/proj-aws/lib/python3.6/site-packages/celery/app/base.py", line 828, in _connection
      'broker_connection_timeout', connect_timeout
    File "/Users/abd/Desktop/proj-aws/lib/python3.6/site-packages/kombu/connection.py", line 181, in __init__
      url_params = parse_url(hostname)
    File "/Users/abd/Desktop/proj-aws/lib/python3.6/site-packages/kombu/utils/url.py", line 34, in parse_url
      scheme, host, port, user, password, path, query = _parse_url(url)
    File "/Users/abd/Desktop/proj-aws/lib/python3.6/site-packages/kombu/utils/url.py", line 52, in url_to_parts
      parts.port,
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/parse.py", line 167, in port
      port = int(port, 10)
    ValueError: invalid literal for int() with base 10: 'xi'

I've been looking around but seems to have no clue how to fix this. Please help me out with this! Much appreciated!


回答1:


I encountered the same problem, and resolved it.

First check (it's very likely) that your AWS access key ID or secret key contains 'xi/' somewhere, and that you have:

BROKER_URL = "sqs://%s:%s@" % (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)

If so, then your problem is in URL unsafe keys, and the fix is:

BROKER_URL = 'sqs://{0}:{1}@'.format(
    urllib.parse.quote(AWS_ACCESS_KEY_ID, safe=''),
    urllib.parse.quote(AWS_SECRET_ACCESS_KEY, safe='')
)

Note: Use urllib.quote if using Python 2.x



来源:https://stackoverflow.com/questions/49417851/django-celery-4-valueerror-invalid-literal-for-int-with-base-10-when-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!