Incorrect test for binary mode in _DownloadReportCheckFormat
in adwords.py the method _DownloadReportCheckFormat was recently changed. The new test for is_binary_mode is probably incorrect:
def _DownloadReportCheckFormat(self, file_format, output):
is_binary_mode = getattr(output, 'mode', 'w') == 'wb'
if (file_format.startswith('GZIPPED_')
and not (is_binary_mode or type(output) is io.BytesIO)):
raise googleads.errors.GoogleAdsValueError('Need to specify a binary'
' output for GZIPPED formats.')
This will incorrectly raise an exception for some valid binary mode combinations (e.g r+b, w+b).
Hello,
Thanks for the report! It looks like this changed back in July. I don't think we expected the use-case to simultaneously read and write from the downloaded report file during an earlier refactoring, so the logic was simplified to what you see above. That said, I don't see a need for us to restrict this usage, so I think it makes sense to go back and update this. It probably won't make it into the update today, but we'll get around to it soon.
Regards, Mark
I'm actually using a tempfile stream for this, but the 'wb' requirement makes a tempfile useless since it can never be read ;)