pythonseleniummutagen

TypeError: object of type 'ID3TimeStamp' has no len()


I have made this code, to get the year from an mp3, and if i print it, it works, but when i write to text box in my webpage, it gives an error(traceback below), but not always, sometimes the error not show, so i suspect it is from the way the mp3 is tagged:

nfo_year = ''
audio_filename = 'myfile.mp3'

f = mutagen.File(audio_filename)

audio = ID3(audio_filename)  # path: path to file


# Year
try:
    nfo_year = audio['TDRC'].text[0]
    print(nfo_year)
except:
    pass

time.sleep(2)
logger_internet.info('Writing Year...')
AB_author = driver.find_element_by_name('year')
AB_author.send_keys(nfo_year)





Traceback (most recent call last):
  File "D:\AB\redacted.py", line 1252, in <module>
    AB_author.send_keys(nfo_year)
  File "D:\AB\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 478, in send_keys
    {'text': "".join(keys_to_typing(value)),
  File "D:\AB\venv\lib\site-packages\selenium\webdriver\common\utils.py", line 150, in keys_to_typing
    for i in range(len(val)):
TypeError: object of type 'ID3TimeStamp' has no len()

my question is: an error on the mp3 tag or am i doing something wrong?


Solution

  • nfo_year is a timestamp object, of type ID3TimeStamp. You have to pass strings to AB_author.send_keys. Since print worked, you can try str(nfo_year).