Kodexempel Python 3

Added by Edward about 4 years ago

Eftersom kodexemplet är specifikt för Python 2 (t.ex. så stöds inte i skrivande stund M2Crypto i Python 3) så tänkte jag slänga upp en fungerande version av kodexemplet för Python 3:

import time
import urllib.parse
import json
import requests
from base64 import b64encode
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.serialization import load_pem_public_key
from cryptography.hazmat.primitives.asymmetric import padding

def print_json(j, prefix=''):
    for key, value in j.items():
        if isinstance(value, dict):
            print('%s%s' % (prefix, key))
            print_json(value, prefix + '  ')
        else:
            print('%s%s:%s' % (prefix, key, value))

username = 'username'
password = 'password'

service = 'NEXTAPI'
utf8 = 'UTF-8'
URL = 'https://api.test.nordnet.se'
API_VERSION = '2'

timestamp = str(int(round(time.time() * 1000)))
usernameBase64 = b64encode(bytes(username, encoding=utf8)).decode(utf8)
passwordBase64 = b64encode(bytes(password, encoding=utf8)).decode(utf8)
timestampBase64 = b64encode(bytes(timestamp, encoding=utf8)).decode(utf8)
authBlob = bytes(usernameBase64 + ':' + passwordBase64 + ':' + timestampBase64, encoding=utf8)

with open("NEXTAPI_TEST_public.pem", "rb") as keyFile:
    pem = keyFile.read()
pemKey = load_pem_public_key(pem, backend=default_backend())
cipher = pemKey.encrypt(authBlob, padding.PKCS1v15())
cipherBase64 = b64encode(cipher).decode(utf8)

headers = {"Accept": "application/json"}
# GET server status
response = requests.get(URL + '/next/' + API_VERSION + '/', headers=headers)
jsonResponse = json.loads(response.text)
print_json(jsonResponse)

# POST login
params = urllib.parse.urlencode({'service': 'NEXTAPI', 'auth': cipherBase64})
response = requests.post(URL + '/next/' + API_VERSION + '/login', params=params, headers=headers)
jsonResponse = json.loads(response.text)
print_json(jsonResponse)


Replies (4)

RE: Kodexempel Python 3 - Added by sunh about 1 month ago

The photos related to your 먹튀검증 are amazing. This is the first time I've ever seen a picture of a cool 꽁머니 . Since when did you take pictures of토토사이트 ? It's very cool. And I'm very interested in the material that you have posted so far about 안전놀이터 . It's hard to find data on 먹튀검증, how did you become an expert? I'm also very interested in 안전놀이터 . I collect a lot of data about 꽁머니 and I have a lot of data about 스포츠중계 . I want to communicate with you. My site names are 먹튀가디언 and 먹튀보안관 . The domain addresses are https://twiddeo.com/ and https://mtboan.com/ . Waiting for a lot of communication. Yes, thank you.And the information on my site 토토안전놀이터 I'm sure you'll admire it. 안전토토사이트 is awesome. I am sure it will be because I am also surprised by your 꽁머니토토 if you visit my site, 메이저안전놀이터 I think there will be a lot of information you want 안전놀이터추천 Or, if you have the purpose of inquiry, it would be nice to say 먹튀사이트조회

RE: Kodexempel Python 3 - Added by sunh about 1 month ago

먹튀검증 That's exactly what I was looking for. 먹튀검증 The country I live in is 안전놀이터 I think this article in 토토사이트 will be very helpful.꽁머니 Do you know about 꽁머니 ? It's not that famous, but you'll find it interesting enough for you to come and talk to 안전놀이터 . Thank you.스포츠중계 In addition, https://mtboan.com/ COVID-19 is becoming a problem all over the world these days.먹튀보안관 I hope there's no harm to you and your family. 먹튀가디언 Thank you https://twiddeo.com/ And the information on my site 토토안전놀이터 I'm sure you'll admire it. 안전토토사이트 is awesome. I am sure it will be because I am also surprised by your 꽁머니토토 And if you visit my site, 메이저안전놀이터 I think there will be a lot of information you want 안전놀이터추천 Or, if you have the purpose of inquiry, it would be nice to say 먹튀사이트조회

RE: Kodexempel Python 3 - Added by sunh about 1 month ago

토토레프리 Hello,먹튀검증 your post was really impressive to me. I'm very happy 먹튀 to finally find the article 먹튀검증업체 I've been searching for. How did you write https://elephonemobile.com/ this article? 먹튀사이트 That's amazing. 메이저놀이터 It is no exaggeration to say that you are an expert in this field. 메이저놀이터 I want to 사설토토 learn how 메이저사설토토 to write from you. Actually, I'm posting on 사설놀이터 a similar site. 안전놀이터 It's not really easy. That's why 안전놀이터 I think you're even greater. 토토사이트 COVID-19 is a problem around the world these days. 메이저토토사이트 Are you okay? I would like to thank you again for always being careful and allowing me to read this. 토토사이트추천 Then have a happy day. 토토사이트 Thank you.

RE: Kodexempel Python 3 - Added by sunh about 1 month ago

안전놀이터검증및연구센터 Hello, 토토사이트분석전문블로그 I read your article for 먹튀검증의새로운패러다임 the first time today. https://kipu.com.ua/ It's a post that https://remarka.kz/ I've never seen before. https://subtitles.ee/ That's amazing. 안전놀이터 You must have 먹튀검증 a genius for writing. 토토사이트 I wish I could write like you. 먹튀사이트검증 When did you start posting like this? 메이저토토사이트 I think it's very old. 메이저안전놀이터 That's how good you are at writing. 안전한사설토토사이트 Actually, 공식안전놀이터 I have a website with 먹튀검증커뮤니티 a similar topic as you. 먹튀검증토토사이트 But I don't have the skill 먹튀검증토토 to write as well as you do. 사설안전놀이터] Thank you again for letting me read this. COVID-19 is becoming a big problem around the world these days. I hope you pass without any problems. Thank you. Have a good day today!Nowadays,토토사이트검증업체 the weather is getting colder every day토토안전놀이터 , so wear warm clothes and watch out for a cold 확실한먹튀검증 It's really cool 검증토토사이트. I'd like to know more information. Just like your 안전한먹튀검증 I have 최고의안전놀이터

(1-4/4)