솔라피 이미지 업로드 #17
-
사용 중인 프로그래밍 언어 및 버전Python 3.9 SDK 버전No response 운영 환경개발 환경 (로컬) 질문/문제 설명안녕하세요, 현재 Python을 이용해 HMAC-SHA256 방식으로 파일 업로드를 구현하고 있으며, 인증은 아래 공식 문서를 참고하고 있습니다: 또한 headers에 다음과 같이 Authorization 값을 포함하고 있으며, Signature는 정상적으로 생성되고 있습니다. 하지만 파일 업로드 시 다음과 같은 오류가 반복되고 있습니다: 이미 다양한 조합으로 확인했으며, 다른 사용자들의 인증 코드 예제도 참고하였습니다. 현재 테스트 중인 API_KEY: 답변 부탁드립니다. 감사합니다. 코드 예시import pandas as pd
import base64
import hashlib
import hmac
import uuid
import requests
import mimetypes
import os
from datetime import datetime, timezone
# 🔐 Solapi 인증 정보
API_KEY = "NCSBMLJ6DWGBKSFS"
API_SECRET = ""
SENDER = ""
# ✅ HMAC-SHA256 인증 헤더 생성
def make_hmac_headers():
salt = str(uuid.uuid4())
date = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
signature = hmac.new(
API_SECRET.encode("utf-8"),
salt.encode("utf-8"),
hashlib.sha256
).hexdigest()
return {
"Authorization": f"HMAC-SHA256 apiKey={API_KEY}, date={date}, salt={salt}, signature={signature}"
}
# ✅ 이미지 업로드
def upload_image(filepath):
mime_type = mimetypes.guess_type(filepath)[0]
with open(filepath, "rb") as f:
encoded = base64.b64encode(f.read()).decode("utf-8")
payload = {
"file": encoded,
"name": os.path.basename(filepath),
"type": "image",
"mime": mime_type
}
res = requests.post(
"https://api.solapi.com/storage/v1/files",
json=payload,
headers=make_hmac_headers()
)
if res.status_code == 200:
return res.json()["fileId"]
else:
print("❌ 이미지 업로드 실패:", res.text)
return None
# ✅ 문자 발송
def send_mms(to, name, academy, image_id):
message = {
"message": {
"to": to,
"from": SENDER,
"type": "MMS",
"subject": f"{academy} 행사 초대",
"text": f"{name} 원장님, 아래 QR 이미지를 확인해주세요.",
"imageId": image_id
}
}
res = requests.post(
"https://api.solapi.com/messages/v4/send",
json=message,
headers=make_hmac_headers()
)
if res.status_code == 200:
print(f"✅ {name}님 문자 전송 완료")
else:
print(f"❌ {name}님 문자 전송 실패:", res.text)
# ✅ CSV에서 참가자 정보 읽기
df = pd.read_csv("participants.csv") # name, academy, phone, participant_id
for _, row in df.iterrows():
name = row["name"]
academy = row["academy"]
phone = row["phone"]
pid = row["participant_id"]
image_path = f"./qrcodes/{name}_{pid}.png"
if os.path.exists(image_path):
image_id = upload_image(image_path)
if image_id:
send_mms(phone, name, academy, image_id)
else:
print(f"⚠️ QR 이미지 없음: {image_path}")시도한 해결 방법No response 기대하는 결과이미지 업로드자체가 안됩니다. 이와 관련하여 해결책이나 추가적인 정보가 필요하다면 도움을 주시면 감사하겠습니다. 확인사항
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Beta Was this translation helpful? Give feedback.
-
|
빠른 응답이 필요해 부득이하게 새로운 게시글로 작성하였습니다. 추가문의사항은 16의 comment로 남기면 될까요?
2025년 4월 8일 (화) 오후 4:21, Subin Lee ***@***.***>님이 작성:
… Closed #17 <#17> as
resolved.
—
Reply to this email directly, view it on GitHub
<#17>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BPAOGLRYQ7MOYMEXIW7YMD32YN2HLAVCNFSM6AAAAAB2VPBX6WVHI2DSMVQWIX3LMV45UABFIRUXGY3VONZWS33OIV3GK3TUHI5E433UNFTGSY3BORUW63R3GE4DOOJSGE4A>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
#16 중복 문의로 해당 문의는 종료하고 #16 문의에서 추가로 답변드리겠습니다.