From 747b28321f3fcece0c1bbfc4dda1f6fce9772543 Mon Sep 17 00:00:00 2001 From: Andrew Straw Date: Fri, 10 Jan 2025 11:26:08 +0100 Subject: [PATCH] lecture as finished --- .../network and web technologies.ipynb | 97 ++++++++++--------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/lectures/lecture-11/network and web technologies.ipynb b/lectures/lecture-11/network and web technologies.ipynb index 9414c35..b2bd153 100644 --- a/lectures/lecture-11/network and web technologies.ipynb +++ b/lectures/lecture-11/network and web technologies.ipynb @@ -219,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -271,28 +271,28 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'{\"name\":\"Darth Vader\",\"height\":\"202\",\"mass\":\"136\",\"hair_color\":\"none\",\"skin_color\":\"white\",\"eye_color\":\"yellow\",\"birth_year\":\"41.9BBY\",\"gender\":\"male\",\"homeworld\":\"https://swapi.py4e.com/api/planets/1/\",\"films\":[\"https://swapi.py4e.com/api/films/1/\",\"https://swapi.py4e.com/api/films/2/\",\"https://swapi.py4e.com/api/films/3/\",\"https://swapi.py4e.com/api/films/6/\"],\"species\":[\"https://swapi.py4e.com/api/species/1/\"],\"vehicles\":[],\"starships\":[\"https://swapi.py4e.com/api/starships/13/\"],\"created\":\"2014-12-10T15:18:20.704000Z\",\"edited\":\"2014-12-20T21:17:50.313000Z\",\"url\":\"https://swapi.py4e.com/api/people/4/\"}'" + "'{\"name\":\"Leia Organa\",\"height\":\"150\",\"mass\":\"49\",\"hair_color\":\"brown\",\"skin_color\":\"light\",\"eye_color\":\"brown\",\"birth_year\":\"19BBY\",\"gender\":\"female\",\"homeworld\":\"https://swapi.py4e.com/api/planets/2/\",\"films\":[\"https://swapi.py4e.com/api/films/1/\",\"https://swapi.py4e.com/api/films/2/\",\"https://swapi.py4e.com/api/films/3/\",\"https://swapi.py4e.com/api/films/6/\",\"https://swapi.py4e.com/api/films/7/\"],\"species\":[\"https://swapi.py4e.com/api/species/1/\"],\"vehicles\":[\"https://swapi.py4e.com/api/vehicles/30/\"],\"starships\":[],\"created\":\"2014-12-10T15:20:09.791000Z\",\"edited\":\"2014-12-20T21:17:50.315000Z\",\"url\":\"https://swapi.py4e.com/api/people/5/\"}'" ] }, - "execution_count": 7, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "response = requests.get('https://swapi.py4e.com/api/people/4/')\n", + "response = requests.get('https://swapi.py4e.com/api/people/5/')\n", "response.text" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -301,7 +301,7 @@ "requests.models.Response" ] }, - "execution_count": 8, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -312,7 +312,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -321,7 +321,7 @@ "str" ] }, - "execution_count": 9, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -332,16 +332,16 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'Date': 'Fri, 10 Jan 2025 09:07:09 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding, Accept, Cookie', 'X-Frame-Options': 'SAMEORIGIN', 'ETag': 'W/\"84f396e29689886d73163ffeea41d4b8\"', 'Allow': 'GET, HEAD, OPTIONS', 'X-Clacks-Overhead': 'GNU Terry Pratchett', 'Content-Encoding': 'gzip', 'Age': '10', 'Cache-Control': 'max-age=14400', 'cf-cache-status': 'HIT', 'Report-To': '{\"endpoints\":[{\"url\":\"https:\\\\/\\\\/a.nel.cloudflare.com\\\\/report\\\\/v4?s=k1tyqow%2BTHfXBggdLlKOGfY3YUvPQIZw2P1EowugfuLk%2F2nzXWw0X%2FjfUeLAhQcRikRxCoEH%2FDEcASi998U%2FcN70vLqQIRPjvoxABihBwDr9ApD2b%2BpBaqDMJ2ujpKeewA%3D%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}', 'NEL': '{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}', 'Server': 'cloudflare', 'CF-RAY': '8ffb83dfbba02c0a-STR', 'alt-svc': 'h3=\":443\"; ma=86400', 'server-timing': 'cfL4;desc=\"?proto=TCP&rtt=4615&min_rtt=4583&rtt_var=1314&sent=4&recv=7&lost=0&retrans=0&sent_bytes=2830&recv_bytes=781&delivery_rate=630387&cwnd=251&unsent_bytes=0&cid=59f4e5c9b008e54f&ts=22&x=0\"'}" + "{'Date': 'Fri, 10 Jan 2025 10:02:19 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding, Accept, Cookie', 'X-Frame-Options': 'SAMEORIGIN', 'ETag': 'W/\"568eba5ec38fb919307c6156c938e302\"', 'Allow': 'GET, HEAD, OPTIONS', 'X-Clacks-Overhead': 'GNU Terry Pratchett', 'Content-Encoding': 'gzip', 'Cache-Control': 'max-age=14400', 'CF-Cache-Status': 'MISS', 'Report-To': '{\"endpoints\":[{\"url\":\"https:\\\\/\\\\/a.nel.cloudflare.com\\\\/report\\\\/v4?s=9AOD88Z9mF%2BfE49ehipfEzpbXz5xs%2B4GabJ8Ds0jAtf4Tdbvyb7hw1bRuVxxgFRriVgTcIoux8CnjfAtBrwXqZGjUsaAZ8ZeOtRZCkSSqU%2BS2gLP%2FGw2qGsrRuLXIL7hproJjLdxEITm48COOw%3D%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}', 'NEL': '{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}', 'Server': 'cloudflare', 'CF-RAY': '8ffbd4ae6d082c0e-STR', 'alt-svc': 'h3=\":443\"; ma=86400', 'server-timing': 'cfL4;desc=\"?proto=TCP&rtt=14991&min_rtt=9209&rtt_var=7584&sent=5&recv=6&lost=0&retrans=0&sent_bytes=2828&recv_bytes=781&delivery_rate=439135&cwnd=252&unsent_bytes=0&cid=b7a8064f0ebc6e2d&ts=256&x=0\"'}" ] }, - "execution_count": 10, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -352,34 +352,35 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'name': 'Darth Vader',\n", - " 'height': '202',\n", - " 'mass': '136',\n", - " 'hair_color': 'none',\n", - " 'skin_color': 'white',\n", - " 'eye_color': 'yellow',\n", - " 'birth_year': '41.9BBY',\n", - " 'gender': 'male',\n", - " 'homeworld': 'https://swapi.py4e.com/api/planets/1/',\n", + "{'name': 'Leia Organa',\n", + " 'height': '150',\n", + " 'mass': '49',\n", + " 'hair_color': 'brown',\n", + " 'skin_color': 'light',\n", + " 'eye_color': 'brown',\n", + " 'birth_year': '19BBY',\n", + " 'gender': 'female',\n", + " 'homeworld': 'https://swapi.py4e.com/api/planets/2/',\n", " 'films': ['https://swapi.py4e.com/api/films/1/',\n", " 'https://swapi.py4e.com/api/films/2/',\n", " 'https://swapi.py4e.com/api/films/3/',\n", - " 'https://swapi.py4e.com/api/films/6/'],\n", + " 'https://swapi.py4e.com/api/films/6/',\n", + " 'https://swapi.py4e.com/api/films/7/'],\n", " 'species': ['https://swapi.py4e.com/api/species/1/'],\n", - " 'vehicles': [],\n", - " 'starships': ['https://swapi.py4e.com/api/starships/13/'],\n", - " 'created': '2014-12-10T15:18:20.704000Z',\n", - " 'edited': '2014-12-20T21:17:50.313000Z',\n", - " 'url': 'https://swapi.py4e.com/api/people/4/'}" + " 'vehicles': ['https://swapi.py4e.com/api/vehicles/30/'],\n", + " 'starships': [],\n", + " 'created': '2014-12-10T15:20:09.791000Z',\n", + " 'edited': '2014-12-20T21:17:50.315000Z',\n", + " 'url': 'https://swapi.py4e.com/api/people/5/'}" ] }, - "execution_count": 11, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -391,7 +392,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -404,10 +405,10 @@ { "data": { "text/plain": [ - "'Darth Vader'" + "'Leia Organa'" ] }, - "execution_count": 12, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -420,37 +421,41 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'C-3PO'" + "'Owen Lars'" ] }, - "execution_count": 13, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "requests.get('https://swapi.py4e.com/api/people/2/').json()['name']" + "requests.get('https://swapi.py4e.com/api/people/6/').json()['name']" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Serving HTTP on port 4448 ...\n", + "Serving HTTP on port 4449 ...\n", "waiting for connection\n", - "Got connection from ('127.0.0.1', 61404)\n", - "GET / HTTP/1.1\n", + "Got connection from ('127.0.0.1', 64530)\n", + "HTTP/1.1 GET /hello\n", + "\n", + "waiting for connection\n", + "Got connection from ('127.0.0.1', 64555)\n", + "l;askdjkfsd;kljfd;lskjfkldsjfklajlkdsfmvmdnsvmngfkljsrjhkfasfasdasdfsafasfasd\n", "\n", "waiting for connection\n" ] @@ -462,7 +467,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[14], line 13\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwaiting for connection\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 13\u001b[0m client_connection, client_address \u001b[38;5;241m=\u001b[39m \u001b[43mlisten_socket\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43maccept\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGot connection from \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(client_address))\n\u001b[1;32m 15\u001b[0m request_data \u001b[38;5;241m=\u001b[39m client_connection\u001b[38;5;241m.\u001b[39mrecv(\u001b[38;5;241m1024\u001b[39m)\n", + "Cell \u001b[0;32mIn[32], line 13\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwaiting for connection\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 13\u001b[0m client_connection, client_address \u001b[38;5;241m=\u001b[39m \u001b[43mlisten_socket\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43maccept\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGot connection from \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(client_address))\n\u001b[1;32m 15\u001b[0m request_data \u001b[38;5;241m=\u001b[39m client_connection\u001b[38;5;241m.\u001b[39mrecv(\u001b[38;5;241m1024\u001b[39m)\n", "File \u001b[0;32m~/anaconda3/envs/wm01-dragon/lib/python3.11/socket.py:294\u001b[0m, in \u001b[0;36msocket.accept\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 287\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21maccept\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 288\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"accept() -> (socket object, address info)\u001b[39;00m\n\u001b[1;32m 289\u001b[0m \n\u001b[1;32m 290\u001b[0m \u001b[38;5;124;03m Wait for an incoming connection. Return a new socket\u001b[39;00m\n\u001b[1;32m 291\u001b[0m \u001b[38;5;124;03m representing the connection, and the address of the client.\u001b[39;00m\n\u001b[1;32m 292\u001b[0m \u001b[38;5;124;03m For IP sockets, the address info is a pair (hostaddr, port).\u001b[39;00m\n\u001b[1;32m 293\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 294\u001b[0m fd, addr \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_accept\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 295\u001b[0m sock \u001b[38;5;241m=\u001b[39m socket(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfamily, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtype, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mproto, fileno\u001b[38;5;241m=\u001b[39mfd)\n\u001b[1;32m 296\u001b[0m \u001b[38;5;66;03m# Issue #7995: if no default timeout is set and the listening\u001b[39;00m\n\u001b[1;32m 297\u001b[0m \u001b[38;5;66;03m# socket had a (non-zero) timeout, force the new socket in blocking\u001b[39;00m\n\u001b[1;32m 298\u001b[0m \u001b[38;5;66;03m# mode to override platform-specific socket flags inheritance.\u001b[39;00m\n", "\u001b[0;31mKeyboardInterrupt\u001b[0m: " ] @@ -472,7 +477,7 @@ "# webserver1.py from https://ruslanspivak.com/lsbaws-part1/\n", "\n", "import socket\n", - "HOST, PORT = '0.0.0.0', 4448\n", + "HOST, PORT = '0.0.0.0', 4449\n", "\n", "listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n", "listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n", @@ -552,7 +557,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 33, "metadata": { "scrolled": true }, @@ -572,7 +577,7 @@ "{'key1': [1.2, {'32': 64, 'c': \"sdfg'dfsg\"}, 3, 4]}" ] }, - "execution_count": 2, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -594,7 +599,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 34, "metadata": {}, "outputs": [ { @@ -603,7 +608,7 @@ "'{\"key1\": [1.2, {\"32\": 64, \"c\": \"sdfg\\'dfsg\"}, 3, 4]}'" ] }, - "execution_count": 3, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" }