Skip to content
Advertisement

How can I convert Json data that coming from Postman convert into Integers in python?

Here I’ve wrote a python script using MQL5 to get total history order from MetaTrader5. here’s the code,

JavaScript

what my requirement is I need to get from_date and to_date parameter from user. so I passed these parameter from Postman Using POST request.here is the payload

JavaScript

And it says,

history_orders = mt.history_orders_total(datetime(fromDate), datetime(toDate)) TypeError: an integer is required (got type str)

how can I convert these Json payloads into integers in python? here my code.

JavaScript

Advertisement

Answer

You care less about the integers, you want datetime objects. You have decided that you want <year>, <month>, <day> as your incoming serialised JSON format for dates.

So you might do:

JavaScript

You might want to add validations, e.g. assert from_date <= to_date etc. depending on your use case.

I also recommend you look into ISO 8601 date formats, as a more standardised way of serialising dates.

Debug Notes, try this based on your comments:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement