I'm creating a very simple example on OSX with python 2.6 but I keep getting:
Traceback (most recent call last):
File "ssl.py", line 1, in <module>
import socket, ssl
File "/Users/Dennis/ssl.py", line 5, in <module>
sslSocket = ssl.wrap_socket(s)
AttributeError: 'module' object has no attribute 'wrap_socket'
Code:
import socket, ssl
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('irc.freenode.net', 7000))
sslSocket = ssl.wrap_socket(s)
print repr(sslSocket.server())
print repr(sslSocket.issuer())
sslSocket.write('Hello secure socket\n')
s.close()
What am I doing terribly wrong?
Thanks!
Dennis
Don't name your script ssl.py, because when you name your script ssl.py and you do import ssl you're importing this same script .
Your script is : ssl.py
When you do an import ssl, it calls itself and that is why you get the AttributeError
Give another name to your script and it should work.
Related
Not able to take ssh of a device using python getting below error.
Tried reinstalling python paramiko but didnt worked
import paramiko
import sys
import time
paramiko.client.SSHClient()
HOST = "192.168.1.11"
USER = "cisco"
PASS = "cisco"
client1=paramiko.SSHClient()
client1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client1.connect(HOST,username=USER,password=PASS)
print "SSH connection to %s established" %HOST
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/testssh.py", line 1, in
import paramiko
File "C:\Python27\lib\site-packages\paramiko__init__.py", line 31, in
from paramiko.client import SSHClient, MissingHostKeyPolicy, AutoAddPolicy, RejectPolicy, WarningPolicy
File "C:\Python27\lib\site-packages\paramiko\client.py", line 24, in
import getpass
File "C:/Users/Administrator/Desktop\getpass.py", line 11, in
remote_conn_pre=paramiko.SSHClient()
AttributeError: 'module' object has no attribute 'SSHClient'
Change this
client1=paramiko.SSHClient()
to this
client1=paramiko.client.SSHClient()
Your best clue is the last line of the stack trace:
line 11, in remote_conn_pre=paramiko.SSHClient()
AttributeError: 'module' object has no attribute 'SSHClient'
(Added some whitespace for clarity)
Here it is saying that on this line, it can't find the property SSHClient in the paramiko class.
I would say to check the paramiko documentation, but you can see that you have successfully called this function on line 4:
paramiko.client.SSHClient()
Which will probably also work on line 11 - as other answers have pointed out, you need to access it through paramiko.client, not just paramiko. You probably also don't need line 4.
I have this python code which getting data from socket's and printing to console. But in working process I getting this error code
Traceback (most recent call last):
File "server.py", line 1, in <module>
import ssl, socket
File "/home/ssl.py", line 20, in <module>
returned from time.time())
AttributeError: 'module' object has no attribute 'wrap_socket'
maybe somebody has any idea how I can fix this issue?
import ssl, socket
sock = ssl.wrap_socket(socket.socket(), 'server.key', 'server.crt', True)
sock.bind( ('', 443) )
sock.listen(10)
while True:
conn, addr = sock.accept()
data = conn.recv(4)
print data
thank you
You most likely have a file named ssl.py in the same directory, as indicated by this part of the error:
File "/home/ssl.py", line 20, in
returned from time.time())
and the script is trying to import that instead of the system level module. If you cannot change the name of that file, try using absolute and relative imports.
I need to use a SOAP service in python and I read about suds so I am using it but I can't move further.
I'm getting an error as soon as I'm creating a Client object.
below is the code
from suds.client import Client
url = 'http://ebay.davismicro.com.cn:9888/api/wishery.php?wsdl'
client = Client(url)
and the error I'm getting is this
Traceback (most recent call last):
File "D:\kshubham\webpractice\alchemytry\apitest1.py", line 12, in <module>
client = Client(url)
File "C:\Python27\lib\site-packages\suds\client.py", line 119, in __init__
sd = ServiceDefinition(self.wsdl, s)
File "C:\Python27\lib\site-packages\suds\servicedefinition.py", line 57, in __init__
self.addports()
File "C:\Python27\lib\site-packages\suds\servicedefinition.py", line 85, in addports
method = (m.name, binding.param_defs(m))
AttributeError: 'NoneType' object has no attribute 'param_defs'
I don't know what I'm doing wrong. Please suggest.
Thanks in advance.
Seems like a bug in suds, give http://docs.python-zeep.org/ a try. It should work, for example:
>>> from zeep import Client
>>> client = Client('http://ebay.davismicro.com.cn:9888/api/wishery.php?wsdl')
>>> client.service.get_globalegrow_sku(start=1, limit=2, sku='foo', identity='bar')
I've been trying out the 'socket' module in Python but whenever I attempt to run this code :
import socket
import sys
host = '192.168.1.1'
port = 23
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except:
print "socket() failed"
sys.exit(1)
Then it dies. Here is the error without the except and try :
Traceback (most recent call last):
File "C:\Documents and Settings\a\Desktop\socket.py", line 1, in <module>
import socket
File "C:\Documents and Settings\a\Desktop\socket.py", line 6, in <module>
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
AttributeError: 'module' object has no attribute 'AF_INET'
I've just started Python(Today) and am in need of help.
I saved it as socket.py but also sock.py ...
import socket
looks into the current directory before Python's standard library. And since your file is called socket.py, it is itself imported instead of the socket standard library module. Rename (don't copy, since that would leave the original file) the file to something else, such as my_socket.py.
I have problems when try to import pywhois module, i can import my own module but still have troubles when import pywhois. I moved the pywhois folder in my project folder domain, the screentshot is below:
This is the import and calling statment below:
import part:
from pywhois import *
calling part:
w = whois('hackbo.com')
self.response.out.write(w)
The problems is it will always throw a http 500 error, error text is below:
Traceback (most recent call last):
File "/home/li/Desktop/google_appengine/google/appengine/ext/webapp/__init__.py", line 700, in __call__
handler.get(*groups)
File "/home/li/Desktop/google_appengine/domain/main.py", line 43, in get
w = whois('hackbo.com')
File "pywhois/__init__.py", line 12, in whois
text = nic_client.whois_lookup(None, domain, 0)
File "pywhois/whois.py", line 157, in whois_lookup
result = self.whois(query_arg, nichost, flags)
File "pywhois/whois.py", line 100, in whois
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
AttributeError: 'module' object has no attribute 'socket'
What is this error means? why i could import my own module but can not import pywhois?
Google App Engine doesn't support the socket module, which pywhois uses. It allows you to import socket, but it's an empty module.
import whois
site = input ("Enter Site : ")
n = whois.whois (site)
print (n)
this is best whois
Enjoy that, easy.