SORU
14 Mayıs 2012, PAZARTESİ


Nasıl'In Python uygulamam tarafından gönderilen tüm HTTP isteği görebilir miyim?

Benim durumumda, HTTPS üzerinden PayPal API çağrısı requests kütüphane kullanıyorum. Ne yazık ki, PayPal bir hata alıyorum, PayPal destek olamaz hatanın ne olduğunu ya da neyin sebep olduğunu anlamaya. Beni istiyorlar "Lütfen tüm istek sağlamak, özeti".

Bunu nasıl yapabilirim?

CEVAP
19 Mayıs 2013, Pazar


Basit bir yöntem: İstekleri (1.yeni sürümleri günlüğü etkinleştirmek x ve daha yüksek.)

İstekler here açıklandığı gibi kontrol etmek için http.client logging modül yapılandırma ayrıntı günlüğü kullanır.

Gösteri

Kod bağlantılı Dokümantasyon bölümünden:

import requests
import logging

# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
try:
    import http.client as http_client
except ImportError:
    # Python 2
    import httplib as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig() 
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

requests.get('https://httpbin.org/headers')

Örnek Çıktı

$ python requests-logging.py 
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): httpbin.org
send: 'GET /headers HTTP/1.1\r\nHost: httpbin.org\r\nAccept-Encoding: gzip, deflate, compress\r\nAccept: */*\r\nUser-Agent: python-requests/1.2.0 CPython/2.7.3 Linux/3.2.0-48-generic\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Content-Type: application/json
header: Date: Sat, 29 Jun 2013 11:19:34 GMT
header: Server: gunicorn/0.17.4
header: Content-Length: 226
header: Connection: keep-alive
DEBUG:requests.packages.urllib3.connectionpool:"GET /headers HTTP/1.1" 200 226

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Klemens Torggler

    Klemens Torg

    11 Mart 2008
  • mahalodotcom

    mahalodotcom

    8 HAZİRAN 2007
  • wafflepwn

    wafflepwn

    14 AĞUSTOS 2008