Zeep: 400 Ошибка клиента: неверный запрос URL - PullRequest
1 голос
/ 04 февраля 2020

Я использую библиотеку Zeep для отправки запроса. Ниже мой код.

from zeep import Client
import logging.config

logging.config.dictConfig({
    'version': 1,
    'formatters': {
        'verbose': {
            'format': '%(name)s: %(message)s'
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
    },
    'loggers': {
        'zeep.transports': {
            'level': 'DEBUG',
            'propagate': True,
            'handlers': ['console'],
        },
    }
})

wsdl = "https://api2.brinkpos.net/Settings.svc?WSDL"
client = Client(wsdl)
result = client.service.GetModifierGroups(accessToken, locationToken)
print(result)

Я получаю сообщение об ошибке в строке client = Client(wsdl). Пожалуйста, найдите полный журнал ниже:

/Users/dilipyadav/githome/elrond/venv/bin/python /Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 65300 --file /Users/dilipyadav/githome/gimli/test/brink_test.py
pydev debugger: process 18141 is connecting

Connected to pydev debugger (build 192.5728.105)
zeep.transports: Loading remote data from: https://api2.brinkpos.net/Settings.svc?WSDL
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2060, in <module>
    main()
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2054, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1405, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1412, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/dilipyadav/githome/gimli/test/brink_test.py", line 28, in <module>
    client = Client(wsdl)
  File "/Users/dilipyadav/githome/elrond/venv/lib/python3.7/site-packages/zeep/client.py", line 68, in __init__
    self.wsdl = Document(wsdl, self.transport, settings=self.settings)
  File "/Users/dilipyadav/githome/elrond/venv/lib/python3.7/site-packages/zeep/wsdl/wsdl.py", line 80, in __init__
    document = self._get_xml_document(location)
  File "/Users/dilipyadav/githome/elrond/venv/lib/python3.7/site-packages/zeep/wsdl/wsdl.py", line 143, in _get_xml_document
    location, self.transport, self.location, settings=self.settings
  File "/Users/dilipyadav/githome/elrond/venv/lib/python3.7/site-packages/zeep/loader.py", line 78, in load_external
    content = transport.load(url)
  File "/Users/dilipyadav/githome/elrond/venv/lib/python3.7/site-packages/zeep/transports.py", line 110, in load
    content = self._load_remote_data(url)
  File "/Users/dilipyadav/githome/elrond/venv/lib/python3.7/site-packages/zeep/transports.py", line 127, in _load_remote_data
    response.raise_for_status()
  File "/Users/dilipyadav/githome/elrond/venv/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api2.brinkpos.net/Settings.svc?WSDL

Process finished with exit code 1

Мне не удается создать сам объект-клиент, поэтому я не могу также регистрировать пост-запрос.

Дайте мне знать, если вам нужна дополнительная информация .

1 Ответ

0 голосов
/ 07 февраля 2020

Мне пришлось переопределить dev wsdl (https://api-devapi01.brinkpos.net/Settings.svc?WSDL), чтобы подключиться к prod (https://api2.brinkpos.net/Settings.svc?wsdl). Поэтому мне пришлось создавать новые объекты ServiceProxy через

https://python-zeep.readthedocs.io/en/master/client.html#creating -new-serviceproxy-objects

В нем упоминалось, как справляться с ситуацией, когда WSDL живет в другой адрес конечной точки.

Рабочий фрагмент ниже:

client = Client(wsdl=wsdl)
service = client.create_service(
    '{http://tempuri.org/}BasicHttpBinding_ISettingsWebService',
    'https://api2.brinkpos.net/Settings.svc?wsdl')
result = service.GetModifierGroups(accesstoken, locationtoken)
print(result)
...