Can I get the history of recent payments to qiwi through the urllib2 module? I tried to do this:

import urllib import urllib2 import json token = 'токен' login = 'номер' parameters = {'rows': '1'} params = urllib.urlencode(parameters) request = urllib2.Request('https://edge.qiwi.com/payment-history/v1/persons/'+login+'/payments', params) request.add_header('Authorization', 'Bearer ' + token) try: urllib2.urlopen(request) except Exception, e: print e.code print e.read() 

But I get it:

 {"serviceName":"payment-history","errorCode":"http.method.not.supported","userMessage":"Method is not supported","dateTime":"2018-08-06T18:09:11.665+03:00","traceId":"08fcf12f42774ae9"} 
  • Tried to work through the library github.com/mostm/pyqiwi ? - gil9red
  • @ gil9red only need to do on standard packages that do not need to be installed - ANDROSHA
  • then see how the sending is done in qiwi in the lib, mb will find the answer :) - gil9red
  • see what http method is needed (GET, PUT, etc.) and try with your hands in curl or analogs - Eugene Dennis
  • @ANDROSHA, once you have deleted your question , I will write in the first one. I did not minus your question. About "I wrote this for the question" - the code in the question should demonstrate the problem. Your code in that question shows that you have never run a function, but expect that the global variable will magically be filled in some way. - insolor

1 answer 1

 import urllib import urllib2 import json token = 'токен' login = 'номер' parameters = {'rows': '1'} params = urllib.urlencode(parameters) request = urllib2.Request('https://edge.qiwi.com/payment-history/v1/persons/{}/payments?{}'.format(login, params)) request.add_header('Authorization', 'Bearer {}'.format(token)) try: response = urllib2.urlopen(request) #далее действия с полученным ответом except Exception, e: print e.code print e.read() 

Try this code, it should work. The problem was that you sent a string ( params ) in the request in the form of a dictionary for POST.