3 практика сделана
This commit is contained in:
parent
709925ebf3
commit
5260aee6b0
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
venv
|
venv
|
||||||
|
.env
|
8
TCP-клиент.py
Normal file
8
TCP-клиент.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
client.connect(('127.0.0.1', 10000))
|
||||||
|
client.sendall(b'hello server')
|
||||||
|
data = client.recv(1024)
|
||||||
|
print(f"Ответ от сервера: {data.decode()}")
|
||||||
|
client.close()
|
21
TCP-сервер.py
Normal file
21
TCP-сервер.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
server.bind(("0.0.0.0", 10000))
|
||||||
|
server.listen(1)
|
||||||
|
print("TCP сервер запущен")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
conn, addr = server.accept()
|
||||||
|
print(f"Подключение от {addr}")
|
||||||
|
|
||||||
|
data = conn.recv(1024)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
conn.sendall(data.upper())
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if data.upper() == b'EXIT':
|
||||||
|
break
|
7
UDP-клиент.py
Normal file
7
UDP-клиент.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
client.sendto(b'hello server', ('127.0.0.1', 8000))
|
||||||
|
data, _ = client.recvfrom(1024)
|
||||||
|
print(f"Ответ от сервера: {data.decode()}")
|
||||||
|
client.close()
|
10
UDP-сервер.py
Normal file
10
UDP-сервер.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
server.bind(('0.0.0.0', 8000))
|
||||||
|
print("UDP сервер запущен")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data, addr = server.recvfrom(1024)
|
||||||
|
print(f"Сообщение от {addr}: {data.decode()}")
|
||||||
|
server.sendto(data.upper(), addr)
|
4
tcp.py
Normal file
4
tcp.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.text[:500])
|
10
tocen.py
Normal file
10
tocen.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import requests
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
TOKEN = os.getenv("GITEA_TOKEN")
|
||||||
|
headers = {"Authorization": f"token {TOKEN}"}
|
||||||
|
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||||
|
print(response.json())
|
16
tocenread.py
Normal file
16
tocenread.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import requests
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
TOKEN = os.getenv("GITEA_TOKENREAD")
|
||||||
|
headers = {"Authorization": f"token {TOKEN}"}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"name": "Practica3RAST",
|
||||||
|
"private": False,
|
||||||
|
"description": "Создали репозиторий с помощью API"
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", headers=headers, json=data)
|
||||||
|
print(response.json())
|
Loading…
Reference in New Issue
Block a user