Задание выполнено

This commit is contained in:
Никита Ниязов 2025-04-26 14:18:36 +03:00
parent 79300570ba
commit e7d8c4383d
10 changed files with 107 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
venv/
.env

6
4zadanie Normal file
View File

@ -0,0 +1,6 @@
import requests
TOKEN = "882062d2e32a319ccb93222d21ca6a9119149be2"
headers = {"Authorization": f"token {TOKEN}"}
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
print(response.json())

BIN
git-bash - Ярлык.lnk Normal file

Binary file not shown.

3
http_requests.py Normal file
View File

@ -0,0 +1,3 @@
import requests
response = requests.get("https://www.vyatsu.ru/")
print(response.text[:500])

19
http_socket.py Normal file
View File

@ -0,0 +1,19 @@
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('vyatsu.ru', 80))
request = (
"GET / HTTP/1.1\r\n"
"Host: vyatsu.ru\r\n"
"User-Agent: python-requests/2.31.0\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"Accept: */*\r\n"
"Connection: keep-alive\r\n"
"\r\n"
)
client.sendall(request.encode())
response = client.recv(4096)
print(response.decode(errors="ignore"))
client.close()

20
repositorcreate Normal file
View File

@ -0,0 +1,20 @@
import os
import requests
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv("token")
headers = {
"Authorization": f"token {TOKEN}",
"Content-Type": "application/json"
}
data = {
"name": "4zadaniepraktika3",
"description": "Репозиторий создан автоматически через pyтhon",
"private": False
}
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", json=data, headers=headers)
print(response.json())

11
tcp_client.py Normal file
View File

@ -0,0 +1,11 @@
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.sendall(b'exit')
client.close()

21
tcp_server.py Normal file
View 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

12
udp_client.py Normal file
View File

@ -0,0 +1,12 @@
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
message = "Hello my Server!"
client.sendto(message.encode(), ('127.0.0.1', 10011)) # Новый порт
data, _ = client.recvfrom(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()

13
udp_server.py Normal file
View File

@ -0,0 +1,13 @@
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server.bind(('0.0.0.0', 10011))
print("UDP сервер запущен на порту 11011")
while True:
data, addr = server.recvfrom(1024)
message = data.decode()
print(f"Сообщение от {addr}: {message}")
modified = message[::-1].upper() + "!!"
server.sendto(modified.encode(), addr)