본문 바로가기

카테고리 없음

소스

반응형

import os
import sys
import urllib.request
import json
import pandas as pd
import matplotlib.pyplot as plt
import time
import random
import requests
import hashlib
import hmac
import base64

class Signature:
    @staticmethod
    def generate(timestamp, method, uri, secret_key):
        message = "{}.{}.{}".format(timestamp, method, uri)
        hash = hmac.new(bytes(secret_key, "utf-8"), bytes(message, "utf-8"), hashlib.sha256)
        
        hash.hexdigest()
        return base64.b64encode(hash.digest())
    
def get_header(method, uri, api_key, secret_key, customer_id):
    timestamp = str(round(time.time() * 1000))
    signature = Signature.generate(timestamp, method, uri, secret_key)
    
    return {'Content-Type': 'application/json; charset=UTF-8', 'X-Timestamp': timestamp, 
            'X-API-KEY': api_key, 'X-Customer': str(customer_id), 'X-Signature': signature}

 

 

uri = '/keywordstool'
method = 'GET'
secretKey   = 'AQAAAAANGumFD/kcO5AApgxJDCSiHaPfRl5MLcwGDagVDmDvbg=='
api_key   =   '01000000000d1ae9850ff91c3b9000a60c490c24a29a13bf2bb7b5781f333628687101af38'
customer_id   =   '2737355'

반응형