Quantcast
Viewing all articles
Browse latest Browse all 14243

Python: Logging TypeError: not all arguments converted during string formatting

Here is a quick reproduction of the issue:

>>> import logging>>> logging.getLogger().setLevel(logging.INFO)>>> from datetime import date>>> date = date.today()>>> logging.info('date={}', date)Traceback (most recent call last):  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 846, in emit    msg = self.format(record)  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 723, in format    return fmt.format(record)  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 464, in format    record.message = record.getMessage()  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 328, in getMessage    msg = msg % self.argsTypeError: not all arguments converted during string formattingLogged from file <stdin>, line 1>>> 

How do I make it work?


This is effectively a special case of Why do I get "TypeError: not all arguments converted during string formatting" trying to substitute a placeholder like {0} using %? - but because the actual formatting step happens outside the user's code, different workarounds are necessary.


Viewing all articles
Browse latest Browse all 14243

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>