Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Python text moderation example fails to run #2

Open
davidefiocco opened this issue May 3, 2019 · 0 comments · May be fixed by #3
Open

Python text moderation example fails to run #2

davidefiocco opened this issue May 3, 2019 · 0 comments · May be fixed by #3

Comments

@davidefiocco
Copy link

davidefiocco commented May 3, 2019

This issue is for a:

- [x] bug report 
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Try to execute https://github.com/Azure-Samples/cognitive-services-content-moderator-samples/blob/master/documentation-samples/python/text-moderation-quickstart-python.py using a Content Moderator resource deployed in Azure.

Any log messages given by the failure

The call to client.text_moderation.screen_text in the example fails with

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

Expected/desired behavior

The call should complete without errors.

OS and Version?

> uname -a
Linux mybox 4.15.0-1041-azure #45-Ubuntu SMP Fri Mar 15 14:41:00 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Versions

azure.cognitiveservices.vision.contentmoderator.version == 1.0.0

Mention any other details that might be useful

The code can be fixed by wrapping the TEXT string in a file-like object as in

import io
screen = client.text_moderation.screen_text(
    text_content=io.StringIO(TEXT),
    language="eng",
    text_content_type="text/plain",
    autocorrect=True,
    pii=True,
    classify=True
)

I am happy to file a PR on this. However, I am not sure about what is the relationship of this repository with https://github.com/Azure-Samples/cognitive-services-python-sdk-samples/blob/master/samples/vision/content_moderator_text_moderation_samples.py (which may have Python examples in better/up-to-date shape).
This failure trickles in the Quickstart documentation too: https://docs.microsoft.com/en-us/azure/cognitive-services/content-moderator/text-moderation-quickstart-python shouldn't work without modifications.

@davidefiocco davidefiocco linked a pull request May 3, 2019 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant