jitesh_tandel
Member
Hi Support,
I am really not happy with Python code step.
I am facing many with Pabbly Python code. I am using Pycharm editor to manage my Python code. The code runs smoothly in my pycharm. When I paste and save the same code, it runs sometimes on "Save and Send Test Request" submit. Python code indentation also unintended when I refresh and open the same step again. However, If I press "Save and Send Test Request" button again it throws an error "Internal server" or sometimes an indentation error not sure why. It is a very frustrating and time-consuming process. I wasted my whole day on it.
Code unintended code
Please help me to fix all those problem so I can focus more on production instead of wasting my time on indentation. How I can check the detail error if I get "Internal server error"?
Thanks,
Jitesh
I am really not happy with Python code step.
I am facing many with Pabbly Python code. I am using Pycharm editor to manage my Python code. The code runs smoothly in my pycharm. When I paste and save the same code, it runs sometimes on "Save and Send Test Request" submit. Python code indentation also unintended when I refresh and open the same step again. However, If I press "Save and Send Test Request" button again it throws an error "Internal server" or sometimes an indentation error not sure why. It is a very frustrating and time-consuming process. I wasted my whole day on it.
import requests
import datetime
import json
SCIENER_CLIENT_ID = '{{ScienerClientId}}'
SCIENER_CLIENT_SECRET = '{{ScienerClientSecret}}'
SCIENER_USERNAME = '{{ScienerUsername}}'
SCIENER_PASSWORD = '{{ScienerPassword}}'
def convert_date_to_unix_ms(date_str, date_format):
try:
date_obj = datetime.datetime.strptime(date_str, date_format)
unix_time = date_obj.timestamp()
milliseconds = int(unix_time * 1000)
return milliseconds
except ValueError:
raise ValueError("Invalid date string or format")
def get_current_unix_ms():
current_time = datetime.datetime.now()
unix_timestamp = current_time.timestamp()
return int(unix_timestamp * 1000)
def sciener_get_lock_id_from_alias(access_token, lock_alias):
api_url = "https://euapi.sciener.com/v3/lock/list"
data = {
"clientId": SCIENER_CLIENT_ID,
"accessToken": access_token,
"lockAlias": lock_alias,
"pageNo": 1,
"pageSize": 20,
"date": get_current_unix_ms(),
}
api_response = requests.get(api_url, params=data)
if api_response.status_code == 200:
lock_list = api_response.json()["list"]
if lock_list:
return lock_list[0]["lockId"]
else:
return False
def sciener_set_custom_passcode(access_token, keyboard_pwd, keyboard_pwd_name, lock_alias, start_date, end_date):
lock_id = sciener_get_lock_id_from_alias(access_token, lock_alias)
if lock_id:
api_url = "https://euapi.sciener.com/v3/keyboardPwd/add"
data = {
"clientId": SCIENER_CLIENT_ID,
"accessToken": access_token,
"lockId": lock_id,
"keyboardPwd": keyboard_pwd,
"keyboardPwdName": keyboard_pwd_name,
"startDate": start_date,
"endDate": end_date,
"addType": 2,
"date": get_current_unix_ms(),
}
api_response = requests.post(api_url, data=data, headers={})
if api_response.status_code == 200:
return api_response.json()
reservation_date_format = "%d/%m/%Y %H:%M:%S"
counter = 0
rcode = ''
rooms = json.loads('')
reserved_rooms = json.loads('')
passcode_creation = ''
new_passcode = ''
sciener_access_token = ''
for reserved_room in reserved_rooms:
for room in rooms:
if room["id"] == reserved_room["id_zak_room"]:
start_dt = reserved_room["dfrom"] + ' ' + "14:55:00"
if passcode_creation == "now":
start_dt_ms = get_current_unix_ms()
else:
start_dt_ms = convert_date_to_unix_ms(start_dt, reservation_date_format)
end_dt_ms = int(start_dt_ms + 11 * 60 * 60 * 1000)
sciener_set_custom_passcode(sciener_access_token, new_passcode, rcode, 101, start_dt_ms, end_dt_ms)
counter += 1
print(json.dumps({"success": "true", "passcode": new_passcode}))
Code unintended code
Please help me to fix all those problem so I can focus more on production instead of wasting my time on indentation. How I can check the detail error if I get "Internal server error"?
Thanks,
Jitesh