Скрипт Python: получение ошибки «pyhaystack.exception.AuthenticationProblem» с сервером Niagara AX - PullRequest
0 голосов
/ 19 июня 2019

Я пытаюсь получить доступ к серверу Niagara AX с использованием аутентификации python, предоставленной в документации pyhaystack, но сталкиваюсь с ошибкой аутентификации.

Я пытался обратиться к документации по pyhaystack (https://pyhaystack.readthedocs.io/en/latest/connect.html#id3),, но не так много информации об аутентификации. Рассматриваемый сервер использует токен csrf при входе через веб-браузер.

import pyhaystack
session = pyhaystack.connect(implementation='ax',
                             uri='http://xx.xx.xx.xx',
                                username='xxxxxx',
                                password='xxxxxx',
                                pint=True)

op = session.nav()
op.wait()
nav = op.result
print(nav)

Использование этого кода обеспечивает следующий вывод:

Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\niagara.py", line 53, in _on_authenticate_done
    (auth, cookies) = operation.result
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\util\state.py", line 97, in result
    self._result.reraise()
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\util\asyncexc.py", line 28, in reraise
    reraise(*self._exc_info)
  File "C:\Program Files\Python37\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\ops\vendor\niagara.py", line 153, in _on_login
    if self._LOGIN_RE.match(response.text):
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 317, in text
    content_encoding = self.content_type_args.get('charset')
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 303, in content_type_args
    self._parse_content_type()
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 325, in _parse_content_type
    content_type = self.headers['content-type']
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 360, in __getitem__
    key, *args, **kwargs)
KeyError: 'content-type'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\ops\grid.py", line 133, in _do_auth_failed
    raise AuthenticationProblem()
pyhaystack.exception.AuthenticationProblem
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\niagara.py", line 53, in _on_authenticate_done
    (auth, cookies) = operation.result
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\util\state.py", line 97, in result
    self._result.reraise()
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\util\asyncexc.py", line 28, in reraise
    reraise(*self._exc_info)
  File "C:\Program Files\Python37\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\ops\vendor\niagara.py", line 153, in _on_login
    if self._LOGIN_RE.match(response.text):
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 317, in text
    content_encoding = self.content_type_args.get('charset')
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 303, in content_type_args
    self._parse_content_type()
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 325, in _parse_content_type
    content_type = self.headers['content-type']
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 360, in __getitem__
    key, *args, **kwargs)
KeyError: 'content-type'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\ops\grid.py", line 133, in _do_auth_failed
    raise AuthenticationProblem()
pyhaystack.exception.AuthenticationProblem
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\niagara.py", line 53, in _on_authenticate_done
    (auth, cookies) = operation.result
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\util\state.py", line 97, in result
    self._result.reraise()
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\util\asyncexc.py", line 28, in reraise
    reraise(*self._exc_info)
  File "C:\Program Files\Python37\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\ops\vendor\niagara.py", line 153, in _on_login
    if self._LOGIN_RE.match(response.text):
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 317, in text
    content_encoding = self.content_type_args.get('charset')
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 303, in content_type_args
    self._parse_content_type()
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 325, in _parse_content_type
    content_type = self.headers['content-type']
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\http\base.py", line 360, in __getitem__
    key, *args, **kwargs)
KeyError: 'content-type'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\rharris\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\191.7479.30\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Users\rharris\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\191.7479.30\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/rharris/.PyCharm2019.1/config/scratches/scratch_3.py", line 10, in <module>
    nav = op.result
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\util\state.py", line 97, in result
    self._result.reraise()
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\util\asyncexc.py", line 28, in reraise
    reraise(*self._exc_info)
  File "C:\Program Files\Python37\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Program Files\Python37\lib\site-packages\pyhaystack\client\ops\grid.py", line 133, in _do_auth_failed
    raise AuthenticationProblem()
pyhaystack.exception.AuthenticationProblem

Мы можем войти на серверный портал через веб-браузер и успешно использовали запросы Selenium для извлечения данных. Мне интересно иметь возможность извлекать данные без дополнительных затрат при использовании браузера.

Что я делаю не так?

...