Skip to content

Commit

Permalink
fix(client): add a workaround for "MalformedPOSTRequest" error
Browse files Browse the repository at this point in the history
Based on some mysterious bugs in OSS,
it is found that modifying a field in the post form can avoid this
error, so add a workaround to temporarily fix this problem

oss error message:
"The body of your POST request is not well-formed multipart/form-data"

PR Closed: #969
  • Loading branch information
zhen.chen authored and AChenQ committed Aug 26, 2021
1 parent 1663484 commit 8095859
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions tensorbay/client/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from ulid import ULID, from_timestamp

from ..dataset import AuthData, Data, Frame, RemoteData
from ..exception import FrameError, InvalidParamsError, OperationError
from ..exception import FrameError, InvalidParamsError, OperationError, ResponseError
from ..label import Label
from ..sensor.sensor import Sensor, Sensors
from ..utility import FileMixin, chunked, locked
Expand Down Expand Up @@ -213,12 +213,25 @@ def _post_multipart_formdata(
file_type = filetype.guess_mime(local_path)
if "x-amz-date" in data:
data["Content-Type"] = file_type
data["file"] = ("", fp, file_type)
multipart = MultipartEncoder(data)

self._client.do(
"POST", url, data=multipart, headers={"Content-Type": multipart.content_type}
)
try:
data["file"] = ("", fp, file_type)
self._post_formdata(url, data)
except ResponseError as error:
if b"MalformedPOSTRequest" in error.response.content:
data["file"] = ("workaroundForMalformedPostRequest", fp, file_type)
self._post_formdata(url, data)
else:
raise

def _post_formdata(self, url: str, data: Dict[str, Any]) -> None:
multipart = MultipartEncoder(data)
self._client.do(
"POST",
url,
data=multipart,
headers={"Content-Type": multipart.content_type},
)

def _put_binary_file_to_azure(
self,
Expand Down

0 comments on commit 8095859

Please sign in to comment.