Import error - No module named http

2,736 views
Skip to first unread message

Nivin Paul

unread,
Mar 18, 2015, 12:24:40 PM3/18/15
to django...@googlegroups.com
I need to call a web service that written using SOAP from a django application , to do that i used the following code but i got error as in the attached screenshot. Please help


import httplib
from xml.dom import minidom

http.request("POST", "/path/to/my/webservice", body=xml, headers = {
"Host": "myservername",
"Content-Type": "text/xml; charset=UTF-8",
"Content-Length": len(xml)
})

print minidom.parseString(http.getresponse().read())
import_error.png

Guilherme Leal

unread,
Mar 18, 2015, 12:28:37 PM3/18/15
to django...@googlegroups.com
you didnt instanciated the HttpConnection Object

Check the docs.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/254af2fd-3406-4b79-a45c-a7c1fffb35d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Farrell

unread,
Mar 18, 2015, 12:29:22 PM3/18/15
to django...@googlegroups.com
Hello Nivin, 

Could you please hit the "switch to copy-and-paste view" link at the top of the tradeback and copy that? The bottom of a traceback is often the most useful for debugging.
Feel free to paste it or relevant code at github gist and send the link if you want to preserve formatting.

--

SHINTO PETER

unread,
Mar 18, 2015, 12:33:08 PM3/18/15
to django...@googlegroups.com
iam to getting same error

------------------------------------------------------------------------------------------------------------------------

Traceback (most recent call last):
  File "test_soap.py", line 4, in <module>

    http.request("POST", "/path/to/my/webservice", body=xml, headers = {
NameError: name 'http' is not defined

---------------------------------------------------------------------------------------------------------------------------

Nivin Paul

unread,
Mar 18, 2015, 12:35:02 PM3/18/15
to django...@googlegroups.com

ImportError at /cdrimport/settings/fraudsummary/disconnect/

No module named http
Request Method: GET
Request URL: http://192.168.12.59:8080/cdrimport/settings/fraudsummary/disconnect/?id=3
Django Version: 1.6.4
Exception Type: ImportError
Exception Value:
No module named http
Exception Location: /home/akhil/Documents/NIVIN/NIVIN/svn/CrossFraudet/branches/V2.1.0/crossfraudet/cdrimport/views/fraud_summary_view.py in <module>, line 24
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/home/akhil/Documents/NIVIN/NIVIN/svn/CrossFraudet/branches/V2.1.0/crossfraudet',
 '/usr/local/lib/python2.7/dist-packages/gevent-1.0.1-py2.7-linux-x86_64.egg',
 '/usr/local/lib/python2.7/dist-packages/greenlet-0.4.2-py2.7-linux-x86_64.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
Server time: Wed, 18 Mar 2015 16:32:22 +0000

Traceback Switch to copy-and-paste view

  • /usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py in get_response
    1.                 resolver_match = resolver.resolve(request.path_info)
      ...
  • /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in resolve
    1.             for pattern in self.url_patterns:
      ...
  • /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in url_patterns
    1.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
      ...
  • /usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py in urlconf_module
    1.             self._urlconf_module = import_module(self.urlconf_name)
      ...
  • /usr/local/lib/python2.7/dist-packages/django/utils/importlib.py in import_module
    1.         __import__(name)
      ...
  • /home/akhil/Documents/NIVIN/NIVIN/svn/CrossFraudet/branches/V2.1.0/crossfraudet/crossfraudet/urls.py in <module>
    1.     url( r'^cdrimport/', include( 'cdrimport.urls' ) ),
      ...
  • /usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py in include
    1.         urlconf_module = import_module(urlconf_module)
      ...
  • /usr/local/lib/python2.7/dist-packages/django/utils/importlib.py in import_module
    1.         __import__(name)
      ...
  • /home/akhil/Documents/NIVIN/NIVIN/svn/CrossFraudet/branches/V2.1.0/crossfraudet/cdrimport/urls.py in <module>
    1. import views
      ...
  • /home/akhil/Documents/NIVIN/NIVIN/svn/CrossFraudet/branches/V2.1.0/crossfraudet/cdrimport/views/__init__.py in <module>
    1. from fraud_summary_view import FraudSummaryListView, FraudDetectionListView, Fraudblock, Frauddisconnect
      ...
  • /home/akhil/Documents/NIVIN/NIVIN/svn/CrossFraudet/branches/V2.1.0/crossfraudet/cdrimport/views/fraud_summary_view.py in <module>
    1. import http
      ...

Guilherme Leal

unread,
Mar 18, 2015, 12:42:56 PM3/18/15
to django...@googlegroups.com
Nivin and Shinto,

You are forgetting to instantiate the HTTPConnection object:

Exemple:


import httplib
from xml.dom import minidom

http = httplib.HTTPConnection("http://mydomain.com")
http.request("POST", "/path/to/my/webservice", body=xml, headers = {
    "Host": "myservername",
    "Content-Type": "text/xml; charset=UTF-8",
    "Content-Length": len(xml)
})

print minidom.parseString(http.getresponse().read())



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Andrew Farrell

unread,
Mar 18, 2015, 12:53:26 PM3/18/15
to django...@googlegroups.com
So it seems like the problem is that you are doing `import http` on line 24 of /home/akhil/Documents/NIVIN/NIVIN/svn/CrossFraudet/branches/V2.1.0/crossfraudet/cdrimport/views/fraud_summary_view.py rather than `import httplib`. Python2 doesn't have a module in the standard library named `http`, only `httplib`.


As an aside, if you are connecting to a SOAP service, you might consider using requests.py or SUDS.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Andrew Farrell

unread,
Mar 18, 2015, 1:24:48 PM3/18/15
to django...@googlegroups.com
Actually, please listen to Guilherme over me; He seems to have correctly spotted the omission.

Mario Gudelj

unread,
Mar 18, 2015, 4:14:15 PM3/18/15
to django...@googlegroups.com

And you should probably use suds for soap based apis.

Reply all
Reply to author
Forward
0 new messages