Error in socket module in Python

0

I'm trying to make a code that creates a TCP client:

import socket

target_host = 'www.google.com'
target_port = 80

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

client.connect((target_host, target_port))
client.send('GET / HTTP /1.1\r\nHost: google.com\r\n\r\n')

response = client.recv(4096)

print(response);

but you're giving this error:

Traceback (most recent call last):
  File "dns.py", line 7, in <module>
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
AttributeError: module 'socket' has no attribute 'socket'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in      apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in <module>
    from urllib.request import urlopen
  File "/usr/lib/python3.5/urllib/request.py", line 88, in <module>
    import http.client
  File "/usr/lib/python3.5/http/client.py", line 739, in <module>
    class HTTPConnection:
  File "/usr/lib/python3.5/http/client.py", line 749, in HTTPConnection
    def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
AttributeError: module 'socket' has no attribute '_GLOBAL_DEFAULT_TIMEOUT'

Original exception was:
Traceback (most recent call last):
  File "dns.py", line 7, in <module>
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
AttributeError: module 'socket' has no attribute 'socket'

The question is how to solve this problem? Thanks in advance for any help!

    
asked by anonymous 21.10.2018 / 04:37

0 answers