Cannot execute... Where is 'CLOUDAMQP_URL' coming from?
Closed this issue · 10 comments
I am new to Python (not new to other languages). I just do not understand where the CLOUDAMQP_URL parameter is coming from. And my Python seems not to understand either...
When I try to run the code as is, I get the following error:
Traceback (most recent call last):
File "/Users/maxparko/Documents/Learning/CloudAMQP/python-amqp-example/example_publisher.py", line 8, in <module>
params = pika.URLParameters(url)
File "/usr/local/lib/python3.6/site-packages/pika/connection.py", line 439, in __init__
self._process_url(url)
File "/usr/local/lib/python3.6/site-packages/pika/connection.py", line 456, in _process_url
if self._validate_host(parts.hostname):
File "/usr/local/lib/python3.6/site-packages/pika/connection.py", line 207, in _validate_host
if not isinstance(host, basestring):
NameError: name 'basestring' is not defined
Process finished with exit code 1
I'm using Python 3.6.1 and pika 0.9.14 as specified.
Thanks for the hint, I really appreciate it your quick reply. However, as I mentioned above, I am new to Python. Also, I am also trying to learn CloudAMQP for my project.
So are you saying that the string CLOUDAMQP_URL
is just a temporary placeholder, and I am supposed to replace it with the actual value of AMQP URL from my instance?
I tried what you suggested (I think). This time, I did not use the os
module. I simply followed the same initial steps from your video: https://youtu.be/BKDoxM9KOJY. Here is my code up to the point where Python crashes on the last line:
import pika
# import os
import logging
logging.basicConfig()
# Parse CLOUDAMQP_URL (fallback to localhost)
url = 'amqp://ndizszsp:rXCOBCV82E556hcuM3qWZT7GSlOOaZ5F@crocodile.rmq.cloudamqp.com/ndizszsp'
params = pika.URLParameters(url)
I am getting the same error as before:
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/maxparko/Documents/Learning/CloudAMQP/python-amqp-example/example_publisher.py
Traceback (most recent call last):
File "/Users/maxparko/Documents/Learning/CloudAMQP/python-amqp-example/example_publisher.py", line 8, in <module>
params = pika.URLParameters(url)
File "/usr/local/lib/python3.6/site-packages/pika/connection.py", line 439, in __init__
self._process_url(url)
File "/usr/local/lib/python3.6/site-packages/pika/connection.py", line 456, in _process_url
if self._validate_host(parts.hostname):
File "/usr/local/lib/python3.6/site-packages/pika/connection.py", line 207, in _validate_host
if not isinstance(host, basestring):
NameError: name 'basestring' is not defined
Process finished with exit code 1
Hi Johan,
I did a quick experiment and ran your example with the default python 2.7 on my iMac. Works great! Fantastic!
So apparently something, somewhere (possibly pika?) does not play nice with the latest production python. How can we fix it?
The problem is my company has committed fully to the latest Python 3.x. I am not sure I can sell the idea of going backwards in time to the old version 2.7.
So the question is: Do you know of any workaround with Pika, or would you recommend another Python AMQP client that works with Python3, or are there any configuration/settings/options somewhere I should set? I do like your CloudAMQP technology. If I can get it to work with the latest Python version, I think we would like to use it... And the last thing I wanna be doing is to dedicate additional resources to managing RabbitAMQP servers on AWS. We got some dozen or more microservices we want to implement.
Any help please?
Use a newer version of Pika. pika==0.11.0
https://www.cloudamqp.com/docs/python.html
Success, it works! Thank you for your support. Simple solution; but makes all the difference.
However, there is still a bit of a problem.
If I do this:
import pika
import os
# Copy the CLOUDAMQP_URL environment variable and paste it (fallback to localhost)
url = 'amqp://ndizszsp:1xqIxoSVeQkzcGNLhhDfddbfSQ3hBS5U@crocodile.rmq.cloudamqp.com/ndizszsp'
... then I get the expected successful result:
... but if I do this:
import pika
import os
# Copy the CLOUDAMQP_URL environment variable and paste it (fallback to localhost)
url = os.environ.get('amqp://ndizszsp:1xqIxoSVeQkzcGNLhhDfddbfSQ3hBS5U@crocodile.rmq.cloudamqp.com/ndizszsp',
'amqp://guest:guest@localhost:5672/%2f')
... then this example code does not run:
My environment:
macOS Sierra 10.12.6
- Rotate your cloudamqp-password. Don't paste passwords on GitHub.
- If you need a fallback you can use
os.getenv(CLOUDAMQP_URL, default_value)
Johan, please do not be concerned about my security at this point. This is just an experimentation for me with completely empty CloudAMQP instance and learning your product. I am rotating my passwords after each copy and paste here in github. In fact I will delete this instance.
However, you are not explaining my problem in a way that I can understand you... Neither, do I see any explanation anywhere in cloudamqp docs regarding `CLOUDAMQP_URL. (Possibly I missed it, and perhaps it's my fault for not finding it)
What exactly is this name: CLOUDAMQP_URL
? It is not mentioned anywhere specifically. Is this a real parameter that Python knows about magically, or is it a placeholder (temporary value) to be replaced by a hardcoded URL string copied and pasted (not "parsed"... that's a wrong word) from CloudAMQP?
Your youtube video (https://youtu.be/BKDoxM9KOJY.) showed how the process works when you copied and pasted the url string and assigned it to pika.URLParamaters
.
I understand that cloudamqp.com is a commercial product. Please try to comprehensively explain how to solve the problem. At this point, sorry, I really do not understand you. Terseness and brevity is good, but only when it is comprehensive and understandable. Otherwise, it is just disappointing and unhelpful.
What you should really be doing here is teaching (educating) a potential customer (if you care about them) how to use your product. Please try to be helpful if at all possible.
CLOUDAMQP_URL in the code example is an environment variable. Environment variables hold values related to the current environment. You need to define it in your system (example: export CLOUDAMQP_URL="your_url_from_cloudamqp_console").