SZman
SZman

Reputation: 141

Python connect to django piston

I have a django piston that generates an image and returns it to the person who connected to the url, and I am having a hard time connecting to the address using Python 2.6. This is my code currently:

#!/usr/bin/env python
import httplib
import urllib

params = urllib.urlencode({})

conn = httplib.HTTPSConnection("192.168.1.112/dj/api/image-gen")
conn.request("GET", "/")

response = conn.getresponse()

print response.status, response.reason
data = response.read()
print data

and here is the error I am getting at the end of the trackback:

in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno 8] nodename nor servname provided, or not known

when I try to connect to another web service like "google.com" the code works fine so I know the problem is with my url, but I am at a loss as to how I fix it.

Upvotes: 2

Views: 382

Answers (1)

Aya
Aya

Reputation: 42120

I suspect you need to change...

conn = httplib.HTTPSConnection("192.168.1.112/dj/api/image-gen")
conn.request("GET", "/")

...to...

conn = httplib.HTTPSConnection("192.168.1.112")
conn.request("GET", "/dj/api/image-gen")

...although you might just as easily be able to use...

data = urllib.urlopen('https://192.168.1.112/dj/api/image-gen').read()

Upvotes: 1

Related Questions