Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image.detect_faces raises KeyError when the image doesn't contain any faces #2749

Closed
talzion12 opened this issue Nov 17, 2016 · 1 comment
Closed
Assignees
Labels
api: vision Issues related to the Cloud Vision API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@talzion12
Copy link

Expected behavior: An empty list is returned from detect_faces.

Ubuntu 16.04
Python 3.5.2
google-cloud version: 0.21.0

Code example

import google.cloud.vision.client
import base64

test_image_base64 = '''iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAZlBMVEU7lNn1+Pr6+/v7/Ps0kdg2
ktguj9jy9/pxruHS5PPi7vfo8fj4+fsijNdBl9rs8/jB2O/F3PDY6PWx0Oxgp9/O4vNWod15s+On
zOtoquC41e6Mveafx+mIueXD2e9/t+Sawudaot4YIx/WAAAFu0lEQVR4nO2d23biOgxAE8dyIDHJ
ALkAgYH+/0+euECBTqFcbEnhaL+0j+wlWb7GjiJBEARBEARBEARBEARBEARBEARBEARBEP4BtDET
hzFaU/8Y/4AxH928zsq4zOp592EMUP8kn4DWy0WWWmVtHMe2/5tmi6XWbyNpis04VU7uhFXpeFMY
6p/mBW26LLnUO0gmWWeG3yDBbH/2OzhuB94ewVT1Vb+9Y10N2RGidapu+DlUuo4Gq6ib6W9+n47T
ZqCtcdKW9wj2imU7of6xTwCTubrVAs+xaj4ZXKZCMU3u9HMk02JgirqpHxHsFethNUbdzO5rgidU
NiRF3eSPCrp6MxxFXZX31phzbPkxEEVdZc8IukStBqEITfZ4ih4VmwFUVICHi8yZ4oz/CA7MC4JO
kf04XK8e6we/k6yYN0W9eyWCn1HcsVbUoxf9HCPGilDkz/UT59ic8RDVjF/NUYcas12gMmsfgn21
WTNVhMqLn6NimacQzV5vhHssz47fzP3kqEPNGeapHqXe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cePKRpyuCJcd3kXSVens5IOUo+Hlfsh9FS3/R3hVM
6yWKNuXVT5zjRZGzYK+4vPNhzuuocslY0L0LmL3W9fN/BhGKl0bhquYyYboO6MXTJdXGC3YPd/wA
mFH5XKYm5YjbUO0KGlZ3P5R7FkC1AuZN8ASYdvago1WzdiAB3KOLXf5Iqqp8x2+ofRswxfzXV8e/
/NJ5MagA7ukdF+XNp+MP+ZmUiyH6OcDApo5vStokrjcwUD9HXxyr9axMfiw7ViXlbF31pZf6Z74G
GF11qzyNlVJ2L2pt/3+c5quu0gMO3xmgjWna3Xw6zsrUpmU2ns53bWPM0KN3gbM0kyPmzewEQRAE
QRAEQRAEQRAEQRAEQRAEQRAEwQ//AapBX5sm4PxNAAAAAElFTkSuQmCC'''

test_image_bytes = base64.b64decode(test_image_base64)

client = google.cloud.vision.Client()

image = client.image(
    content=test_image_bytes,
)

faces = image.detect_faces()
print(faces)

Stack trace

Traceback (most recent call last):
File "test.py", line 42, in
faces = image.detect_faces()
File "/home/tal/virtualenv/lib/python3.5/site-packages/google/cloud/vision/image.py", line 138, in detect_faces
return self._detect_annotation(features)
File "/home/tal/virtualenv/lib/python3.5/site-packages/google/cloud/vision/image.py", line 125, in _detect_annotation
_entity_from_response_type(feature.feature_type, results))
File "/home/tal/virtualenv/lib/python3.5/site-packages/google/cloud/vision/image.py", line 226, in _entity_from_response_type
Face.from_api_repr(face) for face in results[feature_key])
KeyError: 'faceAnnotations'

@daspecster daspecster added api: vision Issues related to the Cloud Vision API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Nov 17, 2016
@daspecster
Copy link
Contributor

Thanks for reporting @meta221!

That was introduced by a refactor that I'm working on.

The PR for the fix is #2750.

@daspecster daspecster self-assigned this Nov 17, 2016
parthea pushed a commit that referenced this issue Jun 4, 2023
* Add initial Secret Manager samples [(#2664)](GoogleCloudPlatform/python-docs-samples#2664)

* Bump secretmanager version [(#2699)](GoogleCloudPlatform/python-docs-samples#2699)

This bumps to the version that doesn't have a bunch of deprecation
warnings.

* Fix a small comment typo [(#2714)](GoogleCloudPlatform/python-docs-samples#2714)

* Add Secret Manager IAM samples [(#2749)](GoogleCloudPlatform/python-docs-samples#2749)

* Add Secret Manager IAM samples

* Use an envvar for the iam user

* Add env var to secrets.

Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com>

* SecretManager update v1beta1->v1 [(#3065)](GoogleCloudPlatform/python-docs-samples#3065)

Client library has been updated: https://pypi.org/project/google-cloud-secret-manager/

* Simplify noxfile setup. [(#2806)](GoogleCloudPlatform/python-docs-samples#2806)

* chore(deps): update dependency requests to v2.23.0

* Simplify noxfile and add version control.

* Configure appengine/standard to only test Python 2.7.

* Update Kokokro configs to match noxfile.

* Add requirements-test to each folder.

* Remove Py2 versions from everything execept appengine/standard.

* Remove conftest.py.

* Remove appengine/standard/conftest.py

* Remove 'no-sucess-flaky-report' from pytest.ini.

* Add GAE SDK back to appengine/standard tests.

* Fix typo.

* Roll pytest to python 2 version.

* Add a bunch of testing requirements.

* Remove typo.

* Add appengine lib directory back in.

* Add some additional requirements.

* Fix issue with flake8 args.

* Even more requirements.

* Readd appengine conftest.py.

* Add a few more requirements.

* Even more Appengine requirements.

* Add webtest for appengine/standard/mailgun.

* Add some additional requirements.

* Add workaround for issue with mailjet-rest.

* Add responses for appengine/standard/mailjet.

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore: some lint fixes [(#3749)](GoogleCloudPlatform/python-docs-samples#3749)

* chore(deps): update dependency google-cloud-secret-manager to v1 [(#3846)](GoogleCloudPlatform/python-docs-samples#3846)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [google-cloud-secret-manager](https://togithub.com/googleapis/python-secret-manager) | major | `==0.2.0` -> `==1.0.0` |

---

### Release Notes

<details>
<summary>googleapis/python-secret-manager</summary>

### [`v1.0.0`](https://togithub.com/googleapis/python-secret-manager/blob/master/CHANGELOG.md#&#8203;100-httpswwwgithubcomgoogleapispython-secret-managercomparev020v100-2020-05-20)

[Compare Source](https://togithub.com/googleapis/python-secret-manager/compare/v0.2.0...v1.0.0)

##### Features

-   release as production/stable ([#&#8203;24](https://www.github.com/googleapis/python-secret-manager/issues/24)) ([39a8cc8](https://www.github.com/googleapis/python-secret-manager/commit/39a8cc8f631569c82d1cbffc6a9bbb440d380683))

</details>

---

### Renovate configuration

:date: **Schedule**: At any time (no schedule defined).

:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

:recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox.

:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples).

* Replace GCLOUD_PROJECT with GOOGLE_CLOUD_PROJECT. [(#4022)](GoogleCloudPlatform/python-docs-samples#4022)

* chore(deps): update dependency pytest to v5.4.3 [(#4279)](GoogleCloudPlatform/python-docs-samples#4279)

* chore(deps): update dependency pytest to v5.4.3

* specify pytest for python 2 in appengine

Co-authored-by: Leah Cole <coleleah@google.com>

* Update dependency pytest to v6 [(#4390)](GoogleCloudPlatform/python-docs-samples#4390)

* chore: update templates

Co-authored-by: Seth Vargo <seth@sethvargo.com>
Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com>
Co-authored-by: gwhitehawk <gwhitehawk@gmail.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Takashi Matsuo <tmatsuo@google.com>
Co-authored-by: Leah Cole <coleleah@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: vision Issues related to the Cloud Vision API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants