fcfangcc / pyxxl

XXL-JOB的Python执行器实现,可以方便的将Python方法注册到XXL-JOB的调度中心上进行管理
https://fcfangcc.github.io/pyxxl/
GNU General Public License v3.0
60 stars 16 forks source link

xxl-job调度任务成功,但回调时会重定向到登录,导致解析问题 #52

Closed Ian-zy1 closed 3 months ago

Ian-zy1 commented 3 months ago

Problem description

xxl-job调度任务成功,但回调时重定向到xxl登录。xxl_client.XXL.callback() 方法尝试从服务器获取JSON数据,但服务器返回了HTML内容(text/html;charset=utf-8),这与预期不符,导致了解析失败。

Steps to reproduce the problem

config = ExecutorConfig(
    xxl_admin_baseurl="http://localhost:20052/xxl-job-admin/api/",
    executor_app_name="ftp-server",
    executor_host="10.1.1.1",
    executor_port=9992,
    access_token='xxl-job',
    debug=True,
)
app = PyxxlRunner(config)

@app.register(name="pushProjectBusinessDataToFtp")
def test_task():
    # you can get task params with "g"
    g.logger.info("get executor params: %s" % g.xxl_run_data.executorParams)
    for i in range(10):
        g.logger.warning("test logger %s" % i)

    return "success 12300"

if __name__ == "__main__":
    app.run_executor()

Specifications like the version of the project, operating system, or hardware

fcfangcc commented 3 months ago

日志里面有具体的失败原因的,看下或者贴出来。还有把issue的信息补全下,不然不好排查

Ian-zy1 commented 3 months ago

exception=ContentTypeError(RequestInfo(url=URL('http://10.3.240.112:20052/toLogin'), method='GET', headers=<CIMultiDictProxy('Host': '10.3.240.112:20052', 'XXL-JOB-ACCESS-TOKEN': 'xxl_job', 'Accept': '/', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Python/3.12 aiohttp/3.10.3')>, real_url=URL('http://10.3.240.112:20052/toLogin')), (<ClientResponse(http://10.3.240.112:20052/xxl-job-admin/api/callback) [302 None]> <CIMultiDictProxy('Location': '/toLogin', 'Content-Length': '0', 'Date': 'Mon, 19 Aug 2024 01:46:10 GMT')> ,), message='Attempt to decode JSON with unexpected mimetype: text/html;charset=utf-8', headers=<CIMultiDictProxy('Content-Type': 'text/html;charset=UTF-8', 'Content-Language': 'en-US', 'Transfer-Encoding': 'chunked', 'Date': 'Mon, 19 Aug 2024 01:46:10 GMT')>)> Traceback (most recent call last): File "/dev/venv/my_venv/lib/python3.12/site-packages/pyxxl/executor.py", line 228, in _run await self.xxl_client.callback(data.logId, start_time, code=200, msg=result) File "/dev/venv/my_venv/lib/python3.12/site-packages/pyxxl/xxl_client.py", line 83, in callback await self._post("callback", payload) File "/dev/venv/my_venv/lib/python3.12/site-packages/pyxxl/xxl_client.py", line 94, in _post r = Response(**(await response.json())) ^^^^^^^^^^^^^^^^^^^^^ File "/dev/venv/my_venv/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1199, in json raise ContentTypeError( aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html;charset=utf-8', url='http://10.3.240.112:20052/toLogin'

fcfangcc commented 3 months ago

pyxxl访问http://10.3.240.112:20052/xxl-job-admin/api/callback然后被服务端重定向到http://10.3.240.112:20052/toLogin'了。服务端忘这个方向排查吧,看看为什么被重定向了

studyletmehappy1 commented 3 months ago

同蹲,解决方法

Ian-zy1 commented 3 months ago

同蹲,解决方法

检查你所使用的xxl-job-admin的配置,查看是否配置了上下文路径;如果没有把ExecutorConfig配置中的xxl_admin_baseurl修改为xxl_admin_baseurl="http://localhost:10052/api/"。

studyletmehappy1 commented 3 weeks ago

感谢❀