httplib exception in Django model

186 views
Skip to first unread message

airween

unread,
Sep 19, 2012, 4:42:24 AM9/19/12
to django...@googlegroups.com
Hello,

here is the sample code:


#!/usr/bin/python
# -*- charset: utf-8 -*-

import sys
import httplib
import base64


httphost, httpport = "www.foo.com", 80
httpuri = "/addrs.php"
 
conn = httplib.HTTPConnection(httphost, httpport)

conn.request("GET", str(httpuri))


r1 = conn.getresponse()
print r1.read()
conn.close()


If I put this code to a model, and that function has called, I get this exception:

(this is from manage.py shell, but through HTTP gives same result)

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/global/htdocs/path/to/docsync/models.py", line 253, in sync
    conn.request("GET", str(h.httpuri))
  File "/usr/lib/python2.6/httplib.py", line 914, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.6/httplib.py", line 951, in _send_request
    self.endheaders()
  File "/usr/lib/python2.6/httplib.py", line 908, in endheaders
    self._send_output()
  File "/usr/lib/python2.6/httplib.py", line 780, in _send_output
    self.send(msg)
  File "/usr/lib/python2.6/httplib.py", line 739, in send
    self.connect()
  File "/usr/lib/python2.6/httplib.py", line 720, in connect
    self.timeout)
  File "/usr/lib/python2.6/socket.py", line 547, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
error: Int or String expected
>>>


What should I do, what is the problem?


Thanks:

a.

Alexis Roda

unread,
Sep 19, 2012, 1:44:22 PM9/19/12
to django...@googlegroups.com
Al 19/09/12 10:42, En/na airween ha escrit:

> File "/usr/lib/python2.6/socket.py", line 547, in create_connection
> for res in getaddrinfo(host, port, 0, SOCK_STREAM):
> error: Int or String expected
> >>>
>
>
> What should I do, what is the problem?

According to the last line it seems that 'host' or 'port' have the wrong
type. Since 'host' must be an string or None the problem seems to be
related with 'port'.

Printing httphost and httpport's type and value before creating the
connection may give you some clue.



HTH

airween

unread,
Sep 20, 2012, 2:33:37 AM9/20/12
to django...@googlegroups.com
Hello,
 
well, you're right :), I printed out the values of those variables, but not types.
But now I see, the type of httpport is 'long' instead of 'int' (it cames from a Django model).

Typecast resolves this problem, thanks :)


a.


HTH

Reply all
Reply to author
Forward
0 new messages