Skip to content

Commit 5e595ba

Browse files
committed
[api] fix uploads
1 parent 3b36e83 commit 5e595ba

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

pywa/api.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def __init__(
3131
self._base_url = f"{base_url}/v{api_version}"
3232
self._session.headers.update(
3333
{
34-
"Content-Type": "application/json",
3534
"Authorization": f"Bearer {token}",
3635
"User-Agent": f"PyWa/{pywa.__version__}",
3736
}
@@ -251,16 +250,11 @@ def upload_media(
251250
Returns:
252251
A dict with the ID of the uploaded media file.
253252
"""
254-
headers = self._session.headers.copy()
255253
return self._make_request(
256254
method="POST",
257255
endpoint=f"/{self.phone_id}/media",
258-
headers=headers,
259-
files={
260-
"file": (filename, media, mime_type),
261-
"messaging_product": (None, "whatsapp"),
262-
"type": (None, mime_type),
263-
},
256+
files=[("file", (filename, media, mime_type))],
257+
data={"messaging_product": "whatsapp"},
264258
)
265259

266260
def get_media_url(self, media_id: str) -> dict:
@@ -767,16 +761,14 @@ def update_flow_json(self, flow_id: str, flow_json: str) -> dict:
767761
]
768762
}
769763
"""
770-
headers = self._session.headers.copy()
771764
return self._make_request(
772765
method="POST",
773766
endpoint=f"/{flow_id}/assets",
774-
headers=headers,
775-
files={
776-
"file": ("flow.json", flow_json, "application/json"),
777-
"name": (None, "flow.json"),
778-
"asset_type": (None, "FLOW_JSON"),
779-
"messaging_product": (None, "whatsapp"),
767+
files=[("file", ("flow.json", flow_json, "application/json"))],
768+
data={
769+
"name": "flow.json",
770+
"asset_type": "FLOW_JSON",
771+
"messaging_product": "whatsapp",
780772
},
781773
)
782774

pywa_async/api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,11 +767,9 @@ async def update_flow_json(self, flow_id: str, flow_json: str) -> dict:
767767
]
768768
}
769769
"""
770-
headers = self._session.headers.copy()
771770
return await self._make_request(
772771
method="POST",
773772
endpoint=f"/{flow_id}/assets",
774-
headers=headers,
775773
files={
776774
"file": ("flow.json", flow_json, "application/json"),
777775
"name": (None, "flow.json"),

pywa_async/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,9 @@ async def upload_media(
13261326
mime_type or mimetypes.guess_type(path)[0],
13271327
)
13281328
elif (url := str(media)).startswith(("https://", "http://")):
1329-
res = await (dl_session or httpx).get(url)
1329+
res = await (
1330+
dl_session or httpx.AsyncClient(follow_redirects=True)
1331+
).get(url)
13301332
try:
13311333
res.raise_for_status()
13321334
except httpx.HTTPError as e:

0 commit comments

Comments
 (0)