๐ฉ๐ป๐ป/python6 [python] Fastapi ์ ํ๋ฆฌ์ผ์ด์ exe ํ์ผ๋ก ๋ฐฐํฌํ๊ธฐ ๊ฐ์์น ์๋น์ค๋ฅผ ์ฝ๋ ๊ณต๊ฐ ์์ด ์ธ๋ถ์์ ์คํํ ์ ์๋๋ก exe ํ์ผ๋ก ๋ณํํ๋ ค ํจํ์ธFastapi ์๋ฒ๋ python์ผ๋ก ์์ฑ๋์ด ์์ผ๋ฏ๋ก pyinstaller ๋ฅผ ์ฌ์ฉํ์ฌ ์คํ ํ์ผ์ ํจํค์งํ๋ ค ํจ์งํ1. main.py ์์ if __name__ == "__main__": ๋ธ๋ก์ผ๋ก ์คํ๋๋ uvicorn ๋ถ๋ฆฌํ๊ธฐ์ด์ pyinstaller๋ application์ ํจํค์งํ ๋ model import ์์์ ์ฐธ์กฐ ๋ฐฉ์์ ์ํฅ์ ๋ฐ์ ์ ์๋ค.if __name__ == "__main__": ๋ธ๋ก์ ์ ์์ ์ผ๋ก ์ธ์ํ์ง ๋ชปํด์ ASGI ์๋ฒ(์ฆ, uvicorn)๋ฅผ ์คํํ์ง ๋ชปํ๋ค.์งํmain.py ์์๋ ๋จ์ํ Fastapi ์ ํ๋ฆฌ์ผ์ด์ ์ ์ ์ํ๋ ์ญํ ๋ง ํ๊ณ , run_server.py์์ main.py๋ฅผ m.. 2024. 11. 5. [python] socket ๋์ ์ฐ๊ฒฐ ์ต๊ทผ์ ๊ฐ๋ฐํ ๊ธฐ๋ฅ ์ค์ 2๊ฐ์ ๋ก๋ด๊ณผ socket ํต์ ์ด ์์๋ค.2๊ฐ์ ๋ก๋ด์ ๋์์ ์์ฒญ์ด ๋ค์ด๊ฐ๋ฉด 1๋ฒ ๋ก๋ด → 2๋ฒ ๋ก๋ด ์ด๋ ๊ฒ ์์๋๋ก ์งํ๋์ด์๋์์ ์งํ๋๋๋ก ํด๋ณด๋ ค๊ณ ํ๋ค.ํ์ธ๋ฉํฐ์ค๋ ๋ ๋ฐฉ์, ๋น๋๊ธฐ ๋ฐฉ์ ๋๊ฐ์ง๊ฐ ์๋ค.๋ฉํฐ์ค๋ ๋๋ฉํฐ์ค๋ ๋๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐ ์์ผ ์ฐ๊ฒฐ์ ๋ณ๋์ ์ค๋ ๋์์ ์ฒ๋ฆฌํ์ฌ ๋ ๊ฐ์ ์ฐ๊ฒฐ์ ๋์์ ๊ด๋ฆฌํ ์ ์๋คimport socketimport threading# ์ฒซ ๋ฒ์งธ ์์ผ ์ฐ๊ฒฐ ํจ์def connect_to_robot_a(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('123.123.123.123', 65432)) # ๋ฐ์ดํฐ ์ ์ก ์์ data = "Hello from .. 2024. 10. 22. [python] fastapi ์ค์๊ฐ ์คํธ๋ฆฌ๋ฐ ์ด๋ฏธ์ง ์ก์ถ ์ด๋ฒ์ ์๋ก ์งํํ ํ๋ก์ ํธ์ ๊ธฐ๋ฅ ์ค ํ๋๋ ์ผ๊ตด ์ธ์์ผ๋ก ํ๋ ๋ก๊ทธ์ธ ๊ธฐ๋ฅ์ด์๋ค์ผ๊ตด ์ธ์ํ๋ model์ cvteam์์ ๋ฐ์์ ๋๋ ui์ ๊ธฐ๋ฅ๋ง ๊ตฌํํ๋ฉด ๋๋ ์ํฉmain.pyfrom fastapi import FastAPIfrom fastapi.responses import StreamingResponseimport cv2app = FastAPI()def generate_frames(): cap = cv2.VideoCapture(0) while True: success, frame = cap.read() if not success: break ret, buffer = cv2.imencode('.jpg', frame) .. 2024. 10. 21. [python] TypeError: 'type' object is not subscriptable โ ๊ฐ์ python3.8 ํ๊ฒฝ์์ ์ฝ๋๋ฅผ ์คํ์ํค๋ ์๋์ ๊ฐ์ ์๋ฌ์ ํจ๊ป ์คํ์ด ์๋์๋คTypeError: 'type' object is not subscriptable ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ ์ง์ ์ ๋ณด๋def test_function1() -> list[str]: ... def test_function2() -> dict: ํ์ ํํธ๋ฅผ ์ง์ ํ ๋ ์๊ธฐ๋ ์ค๋ฅ์์ธ์ ํ์ธํด๋ณด๋, typing ํํธ๋ python3.9๋ถํฐ ์ง์ํ๊ณ ์๋ค โ ๋ฐฉ๋ฒ 1์ฌ์ฉํ๋ python ์ 3.9๋ก ์ ๋ฐ์ดํธํ๋ ๋ฐฉ๋ฒ์ด ์๊ณ โ ๋ฐฉ๋ฒ2python typing ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ์ง์ ํด์ฃผ๋ฉด ๋๋ค.python ๋ฒ์ ์ ์ ํฐ ๋ง ๋จน๊ณ ํด์ผํ๋ ์ด ๋ฐฉ๋ฒ์ ๊ฐ์ถํ๋ค.from typing import List, Dictdef test_.. 2024. 5. 2. [python] Received response with content-encoding: gzip, but failed to decode it. ์๋ฌ : Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect data check') res = requests.get( page_url, headers={ 'User-Agent': utils.get_random_agent() }, timeout=10 ) content = res.content ์์ ๊ฐ์ด ์์ฒญ์, ์๋์ ๊ฐ์ ๋ฉ์ธ์ง์ ํจ๊ป ํฌ๋กค๋ง์ด ์งํ์ด ๋ถ๊ฐํ ์ํฉ์ด ๋ฐ์ํ๋ค. # error Received response with content-encoding: gzip, but failed to decode it.', error(.. 2024. 2. 19. [python] ๋ค์ด๋ฒ ์นดํ ํฌ๋กค๋ง ๋ค์ด๋ฒ ์นดํ ๊ฒ์๊ธ์ ํฌ๋กค๋ง ํ๋ ค ํ๋ค. python requests๋ฅผ ์ด์ฉํด์ ๊ฐ์ง๊ณ ์ค๋ ค๊ณ ํ์ผ๋ ํ์๋์ ์์ ํ ์๋น์ค ์ด์ฉ์ ์ํด ๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํด ์ฃผ์ธ์. IP๊ฐ ์์ฃผ ๋ณ๊ฒฝ๋๋ ๋คํธ์ํฌ ํ๊ฒฝ์์ ๋ก๊ทธ์ธํ๋ ๊ฒฝ์ฐ IP๋ณด์์ ํด์ ํ ์ด์ฉํ์๊ธฐ ๋ฐ๋๋๋ค. ๋ค์ ํ๋ฒ ๋น๋ฐ๋ฒํธ ํ์ธ ํ์๋ฉด ์ด์ฉ์ค์ธ ํ๋ฉด์ผ๋ก ๋์๊ฐ๋ฉฐ, ์์ฑ ์ค์ด๋ ๋ด์ฉ์ ์ ์์ ์ผ๋ก ์ ์ก ๋๋ ๋ฑ๋กํ์ค ์ ์์ต๋๋ค. ์ด๋ ๊ฒ ์ ๊ทผํ ์ ์์์ ์ ์ ์๋ค. ์ด๋ ๊ฒ ๋๋ฉด selenium์ ์ด์ฉํด์ ๋์ ์ผ๋ก ์ ๊ทผํ๊ธฐ๋ก ํ๋ค. ๋ก๊ทธ์ธ id ์ password๋ฅผ ์ ๋ ฅํด์ ์๋์ ์ฝ๋๋ฅผ ์คํํ๋ฉด ๋ก๊ทธ์ธ์ด ์งํ๋จ์ ์ ์ ์๋ค. import time from selenium import webdriver import csv import pandas .. 2024. 1. 30. ์ด์ 1 ๋ค์