Typeerror: fromisoformat: argument must be str

Error: typeerror: fromisoformat: argument must be str

The error message “TypeError: fromisoformat: argument must be str” indicates that the argument passed to the fromisoformat() function is not a string. The fromisoformat() function is used to parse a string representing a date or time in the ISO 8601 format and convert it into a datetime object.

Here is an example that demonstrates the correct usage of fromisoformat() function:


    from datetime import datetime
    
    date_string = '2022-03-15'
    date_object = datetime.fromisoformat(date_string)
    
    print(date_object)
  

In the example above, the date_string variable is a string representing a date in the ISO 8601 format. The fromisoformat() function is used to parse this string and convert it into a datetime object called date_object. Finally, the datetime object is printed to the console.

Make sure that the argument passed to the fromisoformat() function is a valid string in the ISO 8601 format. If the argument is not a string or the string format is incorrect, it will result in the mentioned TypeError.

Read more

Leave a comment