Задать вопрос
gbigliardi
@gbigliardi
senior software developer

Uploading an image using a python script I obtain unexpected APIERRxxxxxxxxx, where is wrong?

Hello,
I'm tryng to upload an image in a group using this script but on "photosV2.commit" I receive an error:

UNKNOWN : Unexpected error, logged by ID : APIERR1478681046926_62

is there a way to understand what is the error ?

this is the script:
step1=ok_api.photosV2.getUploadUrl(gid='53190520930516'
                                          ,aid='53229159252180'
                                          ,count=1)
        print step1
        print 'step1 done ...I obtain this: (see 2 rows below)'
        # {u'upload_url': u'https://gup.mycdn.me/uploadImage?apiToken=Vml3G1rxjH5x%2BQ0Fo9GTPjRQ%2F19vVAS7ajrzE0CeAZwVxvua92aUlvzQRCOUYywWiYo6QmXE1kEb1karWi0T8iph0dapGJd8PwYyoKm7FyNdzQ5mPA5MMvZIMhtGpdQtv9tyVi1phB4%3D&photoIds=k4feX2Y0EkMKBQi1L7sdL6HShvz2V90Yt5B%2BPk1xBquA0NzkgT7XrA%3D%3D', 
        #u'expires': u'2016.11.13 21:22', u'expires_ms': 1479061358474L, u'photo_ids': [u'k4feX2Y0EkMKBQi1L7sdL6HShvz2V90Yt5B+Pk1xBquA0NzkgT7XrA==']}                                          

        print '.. now I unquote the apitoken that is in the upload_url that is returned..' 
        wsplit=step1['upload_url'].split('apiToken=')
        wsplit2=wsplit[1].split('&photoIds=')
        wapitoken_to_unquote = wsplit2[0]
        
        wapitoken_unquoted = urllib.unquote(wapitoken_to_unquote)
        print '.. and this is the token to use in commit..' 
        print wapitoken_unquoted

        print '.. and now upload the image..'
        r = requests.post(step1['upload_url'], files={'testupload.jpg': open('testupload.jpg', 'rb')})
        print r
        print'..I obtain <Response [200]> so is ok...'

        print '.. I try the commit...'
        stoken = wapitoken_unquoted
        step3=ok_api.photosV2.commit(photo_id=step1['photo_ids'][0]
                                    ,comment='some text about the image...'
                                    ,token=stoken)
        print ' ..and I obtain a message like this -> UNKNOWN : Unexpected error, logged by ID : APIERR1478682114969_93'
  • Вопрос задан
  • 497 просмотров
Подписаться 1 Оценить 6 комментариев
Решения вопроса 1
Vjaka
@Vjaka
Платформа игр (Одноклассники)
There is something incorrect in your processing of upload token. Either urllib.unquote breaks something or some other processing harms.
BTW, have you tried without unquoting (leaving %3d untouched, not replaced to =) ?

The internal error for your request is that the parameter is not matching the value expected, it is just invalid. The problem is inside token=stoken arguments

PS: Since there is no official python API from ok (and not planned as well), and APIs you are using are heavily outdated, it might be better to send raw JSON api requests, instead of the wrapper that is possibly changing something unsupported way.

PPS: You can manually test arguments you are passing using online request form built-in for methods:
https://apiok.ru/en/dev/methods/rest/photosV2/phot...
and then
https://apiok.ru/en/dev/methods/rest/photosV2/phot...
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
Alex_woland
@Alex_woland
import pyodnoklassniki

pyodnoklassniki.app_pub_key = 'app_pub_key '
pyodnoklassniki.app_secret_key = 'app_secret_key '
        self.ok_api_Auth = pyodnoklassniki.OdnoklassnikiAPI(access_token='access_token', session_secret_key='session_secret_key')



        photos = self.ok_api_Auth.photosV2.getUploadUrl(permissions='VALUABLE_ACCESS;LONG_ACCESS_TOKEN;GROUP_CONTENT;PHOTO_CONTENT',format = 'json',gid = 'group_id', count = 2)
        #print (photos)
        #print (photos['photo_ids'][0])

        filename1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'repost') + '/1.jpg'
        filename2 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'repost') + '/2.jpg'
        r = requests.post(str(photos['upload_url']), files={'1.jpg': open(filename1, 'rb'),'2.jpg': open(filename2, 'rb')}).json()

        attachment = '{"media": [{' \
                     '"type": "photo", ' \
                     '"list": [' \
                     '{ "id": "' + str(r['photos'][str(photos['photo_ids'][0])]['token'])+ '" },' \
                     '{ "id": "' + str(r['photos'][str(photos['photo_ids'][1])]['token'])+ '" }' \
                     ']},' \
                     '{"type": "link",' \
                     '"url": "' + str('http://ya.ru') + '"},' \
                     '{"type": "text",' \
                     '"text": "' + str('hello') + '"}' \
                     ']}'



        rgroups = self.ok_api_Auth.mediatopic.post(permissions='VALUABLE_ACCESS;LONG_ACCESS_TOKEN;GROUP_CONTENT;PHOTO_CONTENT',format = 'json', attachment=attachment, type='GROUP_THEME', gid='group_id')
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы