Update script to use urrlib for server testing
This commit is contained in:
parent
3ada914040
commit
963585806a
1 changed files with 33 additions and 10 deletions
|
@ -1,22 +1,45 @@
|
||||||
import json
|
import json
|
||||||
import pyotp
|
import pyotp
|
||||||
|
import urllib.request
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
|
serverurl="http://localhost:8000/ungleichotp/verify/"
|
||||||
totp=pyotp.TOTP("PZKBPTHDGSLZBKIZ")
|
totp=pyotp.TOTP("PZKBPTHDGSLZBKIZ")
|
||||||
|
|
||||||
request={}
|
to_send={}
|
||||||
request['name'] = "info@ungleich.ch"
|
to_send['name'] = "info@ungleich.ch"
|
||||||
request['verifyname'] = request['name']
|
to_send['verifyname'] = to_send['name']
|
||||||
|
|
||||||
request['token'] = totp.now()
|
to_send['token'] = totp.now()
|
||||||
request['verifytoken'] = request['token']
|
to_send['verifytoken'] = to_send['token']
|
||||||
|
|
||||||
request['realm'] = "ungleich-admin"
|
to_send['realm'] = "ungleich-admin"
|
||||||
request['verifyrealm'] = request['realm']
|
to_send['verifyrealm'] = to_send['realm']
|
||||||
|
|
||||||
print(json.dumps(request))
|
data = json.dumps(to_send)
|
||||||
|
print(data)
|
||||||
data = json.dumps(request)
|
|
||||||
|
|
||||||
with open("outdata", "w") as fd:
|
with open("outdata", "w") as fd:
|
||||||
fd.write(data)
|
fd.write(data)
|
||||||
fd.write("\n")
|
fd.write("\n")
|
||||||
|
|
||||||
|
|
||||||
|
# Post to test server!
|
||||||
|
#data = urllib.parse.urlencode(bytes(data, encoding="utf-8"))
|
||||||
|
#data = urllib.parse.urlencode(to_send)
|
||||||
|
#data = bytes(data, encoding="utf-8")
|
||||||
|
data = data.encode("utf-8")
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
req = urllib.request.Request(url=serverurl, data=data, headers={'Content-Type': 'application/json'}, method='POST')
|
||||||
|
|
||||||
|
print(req)
|
||||||
|
|
||||||
|
with urllib.request.urlopen(req) as f:
|
||||||
|
print(f.status)
|
||||||
|
|
||||||
|
if f.status == 200:
|
||||||
|
print("all good")
|
||||||
|
print(f.reason)
|
||||||
|
print(f.getcode())
|
||||||
|
|
Loading…
Reference in a new issue