sybrenstuvel / flickrapi

Python Flickr API implementation
https://stuvel.eu/flickrapi
Other
155 stars 33 forks source link

machine_tags and/or userid is not working in search and walk #89

Closed michxi closed 6 years ago

michxi commented 7 years ago

I added to some photos machine_tags. Now I want to see if there is one (or more) photos with this machine tag. Here the tag is an SHA256 of the photo.

ET.dump(self.flickr.photos.search(userid = 'me', machine_tags = 'hash:o="9f38318b6ad55089f68cc2efc16e945a1fea21ba548f7f672416b65c227e675c"'))

results:

<rsp stat="ok">
<photos page="1" pages="0" perpage="100" total="0" />
</rsp>

But if I run the search via https://www.flickr.com/services/api/explore/flickr.photos.search (with userid and machine_tags) I see the correct result (2 photos). By experimentation in explore, I see that the parameter "userid" and the double-quote in machine_tags are critical, but according to logging (as far as i see) both had been incorporated in the request

requests_oauthlib.oauth1_auth DEBUG: Updated body: 'machine_tags=hash%3Ao%3D%229f38318b6ad55089f68cc2efc16e945a1fea21ba548f7f672416b65c227e675c%22&nojsoncallback=1&format=rest&userid=me&page=1&per_page=50&method=flickr.photos.search'

So I'm not quite sure how to proceed.

sybrenstuvel commented 7 years ago

Have you tried different signing methods in the API explorer?

michxi commented 7 years ago

This yield the correct result (* out by me). As I'm using `me´ as user_id, I cannot drop any auth in the possible calling variations in the API explorer:

https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=**API_KEY***&user_id=me&machine_tags=hash%3Ao%3D%229f38318b6ad55089f68cc2efc16e945a1fea21ba548f7f672416b65c227e675c%22&extras=machine_tags%2C+url_o&per_page=500&format=json&nojsoncallback=1&auth_token=***TOKEN***&api_sig=***SIG***

This URL is also perfectly curlable with GET.

If I'm running my unittest again:

2017-08-18 23:41:52,439 flickrapi.core INFO: REST Parser: using xml.etree.cElementTree
2017-08-18 23:41:52,440 flickrapi.core INFO: Calling {'nojsoncallback': 1, 'method': 'flickr.photos.search', 'format': 'etree'}
2017-08-18 23:41:52,440 flickrapi.core DEBUG: Wrapping call <bound method FlickrAPI._flickr_call of [FlickrAPI for key "**API_KEY_l3**"]>(self, (), {'machine_tags': u'hash:o="9f38318b6ad55089f68cc2efc16e945a1fea21ba548f7f672416b65c227e675c"', 'nojsoncallback': 1, 'format': 'rest', 'userid': 'me', 'extras': 'machine_tags', 'timeout': None, 'method': 'flickr.photos.search'})
2017-08-18 23:41:52,441 flickrapi.core DEBUG: Calling {'machine_tags': u'hash:o="9f38318b6ad55089f68cc2efc16e945a1fea21ba548f7f672416b65c227e675c"', 'nojsoncallback': 1, 'format': 'rest', 'userid': 'me', 'extras': 'machine_tags', 'method': 'flickr.photos.search'}
2017-08-18 23:41:52,442 requests_oauthlib.oauth1_auth DEBUG: Signing request <PreparedRequest [POST]> using client <Client nonce=None, signature_method=HMAC-SHA1, realm=None, encoding=utf-8, timestamp=None, resource_owner_secret=****, decoding=utf-8, verifier=None, signature_type=AUTH_HEADER, rsa_key=None, resource_owner_key=**RES_OWNER_l5**, client_secret=****, callback_uri=None, client_key=**API_KEY_l3**>
2017-08-18 23:41:52,442 requests_oauthlib.oauth1_auth DEBUG: Including body in call to sign: True
2017-08-18 23:41:52,443 oauthlib.oauth1.rfc5849 DEBUG: Collected params: [(u'oauth_nonce', u'**NONCE_l7**'), (u'oauth_timestamp', u'**TIMESTAMP_l7**'), (u'oauth_consumer_key', u'**API_KEY_l3**'), (u'oauth_signature_method', u'HMAC-SHA1'), (u'oauth_version', u'1.0'), (u'oauth_token', u'**RES_OWNER_l5**'), (u'machine_tags', u'hash:o="9f38318b6ad55089f68cc2efc16e945a1fea21ba548f7f672416b65c227e675c"'), (u'nojsoncallback', u'1'), (u'format', u'rest'), (u'userid', u'me'), (u'extras', u'machine_tags'), (u'method', u'flickr.photos.search')]
2017-08-18 23:41:52,444 oauthlib.oauth1.rfc5849 DEBUG: Normalized params: extras=machine_tags&format=rest&machine_tags=hash%3Ao%3D%229f38318b6ad55089f68cc2efc16e945a1fea21ba548f7f672416b65c227e675c%22&method=flickr.photos.search&nojsoncallback=1&oauth_consumer_key=**API_KEY_l3**&oauth_nonce=**NONCE_l7**&oauth_signature_method=HMAC-SHA1&oauth_timestamp=**TIMESTAMP_l7**&oauth_token=**RES_OWNER_l5**&oauth_version=1.0&userid=me
2017-08-18 23:41:52,445 oauthlib.oauth1.rfc5849 DEBUG: Normalized URI: https://api.flickr.com/services/rest/
2017-08-18 23:41:52,445 oauthlib.oauth1.rfc5849 DEBUG: Base signing string: POST&https%3A%2F%2Fapi.flickr.com%2Fservices%2Frest%2F&extras%3Dmachine_tags%26format%3Drest%26machine_tags%3Dhash%253Ao%253D%25229f38318b6ad55089f68cc2efc16e945a1fea21ba548f7f672416b65c227e675c%2522%26method%3Dflickr.photos.search%26nojsoncallback%3D1%26oauth_consumer_key%3Da24412af11aaf23a203fb5756fe140e6%26oauth_nonce%3D173512028599250963961503092512%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1503092512%26oauth_token%3D72157685104866665-d75faf8c8b1879c5%26oauth_version%3D1.0%26userid%3Dme
2017-08-18 23:41:52,446 oauthlib.oauth1.rfc5849 DEBUG: Signature: +aoQ79zG3Var1XfL9BchjXJuDiM=
2017-08-18 23:41:52,446 oauthlib.oauth1.rfc5849 DEBUG: Encoding URI, headers and body to utf-8.
2017-08-18 23:41:52,447 requests_oauthlib.oauth1_auth DEBUG: Updated url: https://api.flickr.com/services/rest/
2017-08-18 23:41:52,447 requests_oauthlib.oauth1_auth DEBUG: Updated headers: {'Content-Length': '181', 'Accept-Encoding': 'gzip, deflate, compress', 'Accept': '*/*', 'User-Agent': 'python-requests/2.2.1 CPython/2.7.6 Linux/4.4.0-43-Microsoft', 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'OAuth oauth_nonce="**NONCE_l7**", oauth_timestamp="**TIMESTAMP_l7**", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="**API_KEY_l3**", oauth_token="**RES_OWNER_l5**", oauth_signature="%2BaoQ79zG3Var1XfL9BchjXJuDiM%3D"'}
2017-08-18 23:41:52,447 requests_oauthlib.oauth1_auth DEBUG: Updated body: 'machine_tags=hash%3Ao%3D%229f38318b6ad55089f68cc2efc16e945a1fea21ba548f7f672416b65c227e675c%22&nojsoncallback=1&format=rest&userid=me&extras=machine_tags&method=flickr.photos.search'
2017-08-18 23:41:52,449 urllib3.connectionpool DEBUG: Setting read timeout to None
2017-08-18 23:41:52,734 urllib3.connectionpool DEBUG: "POST /services/rest/ HTTP/1.1" 200 114
2017-08-18 23:41:52,743 flickrapi.core INFO: REST Parser: using xml.etree.cElementTree
2017-08-18 23:41:52,744 TestSomeFlickrRoutines DEBUG: unittest search result: <rsp stat="ok">
<photos page="1" pages="0" perpage="100" total="0" />
</rsp>

It results in total="0" instead of the correct reply of 2.

sybrenstuvel commented 6 years ago

I'm also getting zero results in the API explorer (I've removed user_id="me" because I don't have a photo with that hash), so I can't reproduce this issue.

michxi commented 6 years ago

Use user_id="93816820@N00" and machine_tags='hash:o="75dbdbc9c5acf69de83ac8a2e539258da8d723deb9c7567d7d60bf7a8a36996e"' to reproduce. This look-up via flickr API explorer returns the correct result: https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=f701693ed07b894a0e47c5470ded6497&user_id=93816820%40N00&machine_tags=hash%3Ao%3D%2275dbdbc9c5acf69de83ac8a2e539258da8d723deb9c7567d7d60bf7a8a36996e%22&format=rest

If I pass my user_id instead of "me" in the python API, still empty result.

sybrenstuvel commented 6 years ago

The URL gives me:

<rsp stat="fail">
<err code="100" msg="Invalid API Key (Key not found)"/>
</rsp>

Please give me a way to reliably reproduce your issue, or I cannot fix it.

sybrenstuvel commented 6 years ago

I'm closing this issue due to inactivity.