Skip to content

Commit 7d6875d

Browse files
authored
Using requests library for urlencoding (#71)
1 parent f9faae4 commit 7d6875d

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

codeforces_api/api_request_maker.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import random
2121
import time
2222

23+
import requests
24+
2325

2426
class CodeforcesApiRequestMaker:
2527

@@ -66,15 +68,7 @@ def generate_request(self, method_name, **fields):
6668
fields["time"] = str(int(current_time))
6769
api_signature = str(self._rand) + "/" + method_name + "?"
6870
fields = collections.OrderedDict(sorted(fields.items()))
69-
for i in fields:
70-
api_signature += str(i) + "="
71-
if isinstance(fields[i], list):
72-
for j in fields[i]:
73-
api_signature += str(j) + ";"
74-
else:
75-
api_signature += str(fields[i])
76-
api_signature += "&"
77-
api_signature = api_signature[:-1]
71+
api_signature += requests.urllib3.request.urlencode(fields, safe=";")
7872
api_signature += "#" + str(self._secret)
7973
hashed_signature = hashlib.sha512(api_signature.encode("utf-8"))
8074
fields["apiSig"] = str(self._rand) + str(hashed_signature.hexdigest())

0 commit comments

Comments
 (0)