kolya5544

Untitled

Sep 4th, 2025
2,015
0
Never
10
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. api_key='x'
  2. secret_key='x'
  3. httpClient=requests.Session()
  4. recv_window=str(5000)
  5.  
  6. def genSignature(timestamp, payload):
  7.     param_str= f"{timestamp}{api_key}{recv_window}".encode() + payload
  8.     hash = hmac.new(bytes(secret_key, "utf-8"), param_str, hashlib.sha256)
  9.     signature = hash.hexdigest()
  10.     return signature
  11.  
  12.  
  13. image_path = r"D:\1111.png"
  14. url = "https://api.bybit.com/v5/p2p/oss/upload_file"
  15.  
  16. # params
  17. boundary = "boundary-file"
  18. filename = "test.png"
  19. mimeType = "image/png"
  20.  
  21. with open(image_path, "rb") as f:
  22.     binary_data = f.read()
  23.  
  24. files = MultipartEncoder(
  25.     {
  26.         'upload_file': (
  27.             filename,
  28.             open(image_path, "rb"),
  29.             mimeType
  30.         )
  31.     },
  32.     boundary=boundary
  33. )
  34.  
  35. payload = (
  36.     f"--{boundary}\r\n"
  37.     f"Content-Disposition: form-data; name=\"upload_file\"; filename=\"{filename}\"\r\nContent-Type: {mimeType}\r\n\r\n"
  38. ).encode() + binary_data + f"\r\n--{boundary}--\r\n".encode()
  39.  
  40. timestamp = str(int(time.time() * 10 ** 3))
  41. signature = genSignature(timestamp, payload)
  42. headers = {
  43.     'X-BAPI-API-KEY': api_key,
  44.     'X-BAPI-SIGN': signature,
  45.     'X-BAPI-SIGN-TYPE': '2',
  46.     'X-BAPI-TIMESTAMP': timestamp,
  47.     'X-BAPI-RECV-WINDOW': recv_window,
  48.     "Content-Type": "multipart/form-data; boundary=" + boundary
  49. }
  50.  
  51. response = httpClient.request("POST", url, headers=headers, data=files.to_string())
  52.  
  53. print(response.status_code)
  54. print(response.text)
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment