import os
import time
import hmac, hashlib
import urllib.parse
import urllib.request
import ssl
import json

os.environ['TZ'] = 'GMT+0'

datetime=time.strftime('%y%m%d')+'T'+time.strftime('%H%M%S')+'Z'
method = "DELETE"
path = "/v2/providers/seller_api/apis/api/v1/marketplace/seller-products/83358541"

message = datetime+method+path

#replace with your own accesskey
accesskey = "****"
#replace with your own secretKey
secretkey = "****"

#********************************************************#
#authorize, demonstrate how to generate hmac signature here
signature=hmac.new(secretkey.encode('utf-8'),message.encode('utf-8'),hashlib.sha256).hexdigest()
authorization  = "CEA algorithm=HmacSHA256, access-key="+accesskey+", signed-date="+datetime+", signature="+signature
#print out the hmac key
#print(authorization)
#********************************************************#

# ************* SEND THE REQUEST *************
#url = "http://api-gateway-it-ext.coupang.com"+path
url = "https://api-gateway.coupang.com"+path

req = urllib.request.Request(url)

req.add_header("Content-type","application/json;charset=UTF-8")
req.add_header("Authorization",authorization)

req.get_method = lambda: method

#skipping for ssl cert.
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

try:
  resp = urllib.request.urlopen(req, context=ctx)
except urllib.request.HTTPError as e:
    print(e.code)
    print(e.reason)
except urllib.request.URLError as e:
    print(e.errno)
    print(e.reason)
else:
    # 200
    body = resp.read().decode(resp.headers.get_content_charset())
    print(body)