Hara
Hara

Reputation: 71

python bs4 requests: ValueError: unconverted data remains:

i did go through the existing questions, but for my code there is no hint given after the ValueError as to where exactly the data remained unconverted. code below. please help:

str_time = 'Fri, 16 Sep 2016 14:28:14 +0530'
obj_time = datetime.datetime.strptime(str_time[:25],'%a, %d %b %Y %H:%M:%S')
obj_time_rounded = obj_time.replace(hour=0, minute=0, second=0, microseconds =0)

today = datetime.datetime.today()
today_rounded = today.replace(hour=0, minute=0, second=0, microsecond=0)
delta = (today_rounded - obj_time_rounded)

if delta.days == 0:
   ....
   ....

error:
File "C:\Users\dell\AppData\Local\Programs\Python\Python35\lib\_strptime.py", line 340, in _strptime
data_string[found.end():])
ValueError: unconverted data remains:

Upvotes: 1

Views: 602

Answers (1)

JPv
JPv

Reputation: 23

I had this same issue (no value after ValueError: unconverted data remains:). After a very unproductive hour (or so), I finally figured out I hadn't properly stripped my text. Make sure you don't have a newline character in your data as I did...strptime considers this a data point.

E.g. 'Sat Mar 8 09:00:01 2014\n'

Upvotes: 1

Related Questions