Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: type object 'socket' has no attribute 'socket'

Tags:

python

sockets

import socket
from socket import *

conn = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3))

I'm facing this error:

AttributeError: type object 'socket' has no attribute 'socket'
like image 286
King Nick Avatar asked Nov 26 '25 14:11

King Nick


2 Answers

If you import all library don't need to name library before method:

from socket import *
socket.socket # AttributeError: type object 'socket' has no attribute 'socket'
from socket import *
socket # <class 'socket.socket'>

or maybe :

import socket
socket.socket # <class 'socket.socket'>
like image 162
ᴀʀᴍᴀɴ Avatar answered Nov 28 '25 03:11

ᴀʀᴍᴀɴ


import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print("Socket is created")

I fixed these changes my codes and work.

like image 22
Kübra Avatar answered Nov 28 '25 03:11

Kübra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!