Msg.html not saving correctly

I have an email come in and I save the html using msg.html into a text field into my database. I then later need to use that html to parse a date out of it.

When I try to parse it everything will work until I try to put the string into a strptime object. It says there is unconverted data that remains. I then go to the data that saves the html and copy and paste the same thing in there. It will then begin to work. Is it not saving it correctly? Does it save something weird. This also happens when I first get the email. I need to parse that date when it comes in and it gives me the same error. I have tried to convert it into a string using str() and also have tried to append something onto the string. I have also tried to delete it completely and put it back. Something is weird with the msg.html but I cant figure it out.

Here are two strings I get after parsing the two different emails. The one on the top is the email that working because I had copied and pasted it back into the database. The one on the bottom is one that is not working giving me the error of Unconverted data remains. These strings were directly printed from the program after parsing. Below those is the code that turns those strings into a strptime date.

Apr 11, 2023 5:43pm
Sep 28, 2023 1:03pm

β€˜β€™β€˜python
orderCompleted = local_Time.localize(datetime.strptime(str(orderCompleted), β€˜%b %d, %Y %I:%M%p’), local_Time)
β€˜β€™β€™

I have fixed the problem. I believe that it was saving some formatting that I could not see. When I copy and pasted it I believe it would get rid of that formatting. I have included the code I used to insure that the string is only ascii characters in case someone runs into this problem.

β€˜β€™β€˜python
β€œβ€.join(s for s in orderCompleted if ord(s)>31 and ord(s)<126)
β€˜β€™β€™

orderCompleted is the string I needed to take out any none ascii characters.

1 Like