|
9 | 9 | # 1. 로그인 정보 |
10 | 10 | |
11 | 11 | password = "password2!" |
12 | | -# 초기 device_id는 임의로 설정하거나, 서버에서 새로 발급받을 수 있음 |
13 | 12 | initial_device_id = "test_device_123" |
14 | 13 |
|
15 | 14 | # 2. 로그인 요청 |
|
20 | 19 | } |
21 | 20 | login_headers = { |
22 | 21 | "Content-Type": "application/json", |
23 | | - "X-Device-ID": initial_device_id # 로그인 시 X-Device-ID를 보냄 |
| 22 | + "X-Device-ID": initial_device_id |
24 | 23 | } |
25 | 24 |
|
26 | 25 | try: |
27 | 26 | login_response = requests.post(LOGIN_ENDPOINT, json=login_payload, headers=login_headers) |
28 | | - login_response.raise_for_status() # HTTP 오류 발생 시 예외 발생 |
| 27 | + login_response.raise_for_status() |
29 | 28 |
|
30 | 29 | access_token = login_response.headers.get("Authorization") |
31 | 30 | received_device_id_raw = login_response.headers.get("X-Device-ID") |
|
36 | 35 | print(f"응답 본문: {login_response.text}") |
37 | 36 | exit() |
38 | 37 |
|
39 | | - final_device_id = initial_device_id # 기본값은 초기 device_id |
| 38 | + final_device_id = initial_device_id |
40 | 39 | if received_device_id_raw: |
41 | 40 | final_device_id = received_device_id_raw.split(',')[0].strip() |
42 | 41 | print(f"로그인 응답에서 X-Device-ID를 추출했습니다: {final_device_id}") |
43 | 42 | else: |
44 | 43 | print("로그인 응답에서 X-Device-ID 헤더를 찾을 수 없습니다. 초기 device_id를 사용합니다.") |
45 | 44 |
|
46 | | - print("로그인 성공! (이전 단계에서 얻은 토큰 사용)") |
| 45 | + print("로그인 성공!") |
47 | 46 | print(f"Access Token: {access_token}") |
48 | 47 | print(f"Final X-Device-ID: {final_device_id}") |
49 | 48 |
|
|
55 | 54 | "X-Device-ID": final_device_id |
56 | 55 | } |
57 | 56 |
|
58 | | - # stream=True를 사용하여 응답을 스트리밍 방식으로 처리 |
59 | 57 | with requests.get(SSE_ENDPOINT, headers=sse_headers, stream=True) as sse_response: |
60 | | - sse_response.raise_for_status() # HTTP 오류 발생 시 예외 발생 |
| 58 | + sse_response.raise_for_status() |
61 | 59 |
|
62 | 60 | print("SSE 연결 성공! 이벤트를 수신 중...") |
63 | 61 | for line in sse_response.iter_lines(): |
64 | 62 | if line: |
65 | 63 | decoded_line = line.decode('utf-8') |
66 | 64 | print(decoded_line) |
67 | | - # 연결이 끊어지면 루프 종료 |
68 | 65 | if not line and sse_response.raw.closed: |
69 | 66 | print("SSE 연결이 종료되었습니다.") |
70 | 67 | break |
71 | | - time.sleep(0.1) # 너무 빠르게 읽지 않도록 잠시 대기 |
| 68 | + time.sleep(0.1) |
72 | 69 |
|
73 | 70 | except requests.exceptions.RequestException as e: |
74 | 71 | print(f"요청 중 오류 발생: {e}") |
|
0 commit comments