Could someone help me with this project? 09-16-2018, 08:40 AM
#1
Here is my code:
Could someone help me:
1. figure out what's causing the syntax error:
2. understand my own code better? I really want to understand the code better so that I can reprogram it differently.
Thanks so much.
Best,
ghostheadx9
Code:
import sys, socket
try:
rfc_number = int(sys.argv[1])
except (IndexError, ValueError):
print('Must supply an RFC number as first argument')
sys.exit(2)
host = 'www.ietf.org'
port = 80
sock = socket.create_connection((host, port))
req = (
'GET/rfc/rfc{rfcnum}.txt HTTP/1.1\r\n',
'Host: {host}:{port}\r\n',
'User-Agent: Python {version}\r\n',
'Connection: close\r\n',
'\r\n'
)
req = req.format(
rfcnum=rfc_number,
host=host,
port=port,
version=sys.version.info[0]
)
sock.sendall(req.encode('ascii'))
rfc_raw = bytearray()
while True:
buf = sock.recv(4096)
if not len(buf):
break
rfc_raw += buf
rfc = rfc_raw.decode('utf-8')
print(rfc)Could someone help me:
1. figure out what's causing the syntax error:
Code:
adam@adam-Inspiron-5558:~/.PyCharmCE2018.2/config/scratches$ python firstTCP_program.py 782
Traceback (most recent call last):
File "firstTCP_program.py", line 21, in <module>
req = req.format(
AttributeError: 'tuple' object has no attribute 'format'2. understand my own code better? I really want to understand the code better so that I can reprogram it differently.
Thanks so much.
Best,
ghostheadx9


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)