Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ability to upload images. #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions pyshopee2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ def _create_parameter_url(self, url, parameter):
return url + par
return url

def _build_request(self, uri, method, body):
def _build_request(self, uri, method, body=None, files=None):
method = method.upper()
headers = {'Content-Type': 'application/json'}
timest = self._make_timestamp()
uri = self.BASE_API_URL + uri
url = self.host + uri
Expand All @@ -174,8 +173,14 @@ def _build_request(self, uri, method, body):
sign = self._api_sign(uri, timest)
parameter = self._make_default_parameter(timest, sign)
# parameter = self.set_additional_parameter(parameter, sign, timest, self.access_token)
req = Request(method, url, headers=headers)
req = Request(method, url)
if files:
req.data = body
req.files = files

if body:
req.headers = {'Content-Type': 'application/json'}

if method in ["POST", "PUT", "PATH"]:
req.json = body
else:
Expand Down Expand Up @@ -215,18 +220,16 @@ def execute(self, uri, method, body=None):
''' defalut timeout value will be 10 seconds
'''
#parameter = self._make_default_parameter()
if body.get("timeout"):
if body.get("timeout", None):
timeout = body.get("timeout")
body.pop("timeout")
else:
timeout = 10

#if body is not None:
#parameter.update(body)

req = self._build_request(uri, method, body)
print(req.params)
print(req.url)
files = body.pop("files", None)
req = self._build_request(uri, method, body, files)
prepped = req.prepare()

s = Session()
Expand Down