Azure-sdk-for-python: Content Moderator: Generator in screen_text is actually a File

Created on 28 Nov 2019  路  7Comments  路  Source: Azure/azure-sdk-for-python

I am using the Content Moderator sample for text moderation, and have the screen_text() API call. In the SDK it says this function needs a Generator object for its text_content parameter. But using one produces an error:

AttributeError: 'generator' object has no attribute 'read'

This seems to be because it expects a File object instead of a Generator, as a File object does have a read attribute. I used a File object instead and it works as intended.

So either the requirement for a Generator object listed in the SDK should change to require a File object, or the source code should change so it actually does accept a Generator object.

The screen_text() function:

screen = client.text_moderation.screen_text(
    language="eng", text_content_type="text/plain", text_content=text_gen, autocorrect=True, pii=True, classify=True)
assert isinstance(screen, Screen)
Autorest Issue Client Cognitive - Content Moderator Service Attention bug customer-reported

All 7 comments

Hi @wiazur
You're right, the doc is incorrect. That should be IO type in the documentation.

In the recent version of our code generator, we actually accept a little more types. I created an issue in our code generator repo to be sure the doc is correct.

This package will eventually use the new code generator in a close future, and that will solve this issue automatically, I'm keeping it open until then.

Thanks for the report!

Thanks @Imazuel, very helpful! Do you happen to know when the Swagger will get regenerated, this month perhaps? Thanks so much for filing that bug.

More probably early 2020, I don't have a strong ETA yet, we're finishing the new code generator

Is this resolved now with the codegen fix or does something need to get released?

@Petermarcu We did not re-release all autogen Cognitive with the new generator, I would expect this to be solved if we do so.

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @swiftarrow11.

Ok, I marked it as the next step being on the Service to regenerate and ship.

Was this page helpful?
0 / 5 - 0 ratings