Search code examples
pythonrediscloud9-ide

Getting Redis to run in Python on Cloud9


I have seen examples getting Redis to run on Python on Cloud9, but I keep hitting a fundamental error.

Just running:

import os
import redis
#r = redis.Redis()

Yields module and socket errors as follows:

Traceback (most recent call last):

File "/home/ubuntu/workspace/redis-trial.py", line 5, in <module> from redis.client import Redis, StrictRedis                                                                                                                                                                                                          
File "/usr/local/lib/python2.7/dist-packages/redis/__init__.py", line 1, in <module> from redis.client import Redis, StrictRedis                                                                                                                                                                                                         
File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 10, in <module> from redis.connection import (ConnectionPool, UnixDomainSocketConnection,                                            
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 6, in <module> import socket                                                                                                                                                                                                                                       
File "/home/ubuntu/workspace/socket.py", line 5, in <module> s = socket.socket() # Create a socket object                                                                                                                                                                                             TypeError: 'module' object is not callable

(Yes, I know I commented out the r = redis.Redis(), but I get the same problem regardless whether I leave it in).

I have tried other configurations such as:

r = redis.Redis(host='localhost', port=6379, db=0, password=None, socket_timeout=None, connection_pool=None, charset='utf-8', errors='strict', unix_socket_path=None)

But it keeps crapping out -- looks like at the initial import.

I have Redis-cli running on the server. Running redis-cli ping yields the correct PONG response.

Ideas?


Solution

  • You have a local file called socket.py which is shadowing the standard library socket module. Rename your file.