본문 바로가기
카테고리 없음

test

by 홍당무252 2025. 5. 20.
반응형

import requests import hashlib import hmac import time import json # 쿠팡 파트너스 API 정보

access_key =0dedefbd-ba10-47e2-a400-9490921214e7

secret_key = 6a883c4f27a5be2c3dbdf5779e74343d443b44fa

partner_id = 'AF3169495' # 요청 정보 설정 method = 'GET' path = '/v2/providers/affiliate_open_api/apis/openapi/products/search' domain = 'https://api-gateway.coupang.com' timestamp = str(int(time.time() * 1000)) # HMAC-SHA256 서명 생성 함수 def generate_signature(method, path, timestamp): message = f'{method} {path} {timestamp}' signature = hmac.new(secret_key.encode('utf-8'), message.encode('utf-8'), hashlib.sha256).hexdigest() return signature # 서명 생성 signature = generate_signature(method, path, timestamp) # 요청 헤더 설정 headers = { 'Authorization': f'CEA algorithm=HmacSHA256, access-key={access_key}, signed-headers=content-type;host;x-date, signature={signature}', 'Content-Type': 'application/json', 'x-date': timestamp, } # 검색할 키워드 설정 keyword = '노트북' # API 요청 파라미터 설정 params = { 'keyword': keyword, 'limit': 10, } # API 요청 보내기 response = requests.get(domain + path, headers=headers, params=params) # 응답 확인 if response.status_code == 200: result = response.json() print(json.dumps(result, indent=2, ensure_ascii=False)) else: print('Error:', response.status_code, response.text)

반응형