Files
F6--/其它系统脚本/打印单查询打印单下载模板.ipynb
T
2026-01-30 11:28:35 +08:00

279 lines
17 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "UnicodeDecodeError",
"evalue": "'utf-8' codec can't decode byte 0xac in position 0: invalid start byte",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mUnicodeDecodeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-3-87aa11f4b742>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mfile\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"941b03aaa8f34d51a6811619c5402771.jasper\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"r\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mcontent\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcontent\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mfile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;32mc:\\Users\\admin\\.conda\\envs\\F6processing\\lib\\codecs.py\u001b[0m in \u001b[0;36mdecode\u001b[1;34m(self, input, final)\u001b[0m\n\u001b[0;32m 320\u001b[0m \u001b[1;31m# decode input (taking the buffer into account)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 321\u001b[0m \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbuffer\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 322\u001b[1;33m \u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mconsumed\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_buffer_decode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrors\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfinal\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 323\u001b[0m \u001b[1;31m# keep undecoded input until the next call\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 324\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbuffer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mconsumed\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mUnicodeDecodeError\u001b[0m: 'utf-8' codec can't decode byte 0xac in position 0: invalid start byte"
]
}
],
"source": [
"file = open(\"941b03aaa8f34d51a6811619c5402771.jasper\", \"r\")\n",
"content = file.read()\n",
"print(content)\n",
"file.close()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"cookies_str = 'print-serverSESSIONID=C4blK6XZ3R4cPoz8oME3-7zpVyryfbEqaCIrO7lK; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%222268275546837446%22%2C%22first_id%22%3A%221753edeb75a603-0155d23aa05675-3d634f03-1327104-1753edeb75b347%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%221753edeb75a603-0155d23aa05675-3d634f03-1327104-1753edeb75b347%22%7D; _yg_prod=EkX_f7K7eYt61spccZtpCE7FHwA2I5PROPsPCa8-iC3ASlLYfszIPQQqjcJjPPEZL0J2pO07cfpwVG-vQiXuF_g96wpnVRU7RGb1e5vW9kCewwIM05-hAXqyHZDn6PTH2oT4TDPMGRGOiijcH2MfVIFSNGm_aG9C3g..'\n",
"\n",
"cookies_str = cookies_str.encode('utf-8').decode('latin-1')\n",
"\n",
"cookie_dict = {item.split('=')[0]: item.split('=')[1]\n",
" for item in cookies_str.split('; ')}"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: '941b03aaa8f34d51a6811619c5402771.jasper'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-4-d0109545ead5>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 26\u001b[0m }\n\u001b[0;32m 27\u001b[0m \u001b[0mfile_path\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"941b03aaa8f34d51a6811619c5402771.jasper\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 28\u001b[1;33m \u001b[1;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_path\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"rb\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 29\u001b[0m \u001b[0mfiles\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;34m\"file\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mfile_path\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 30\u001b[0m \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpost\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mheaders\u001b[0m \u001b[1;33m,\u001b[0m\u001b[0mcookies\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcookie_dict\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mfiles\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfiles\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '941b03aaa8f34d51a6811619c5402771.jasper'"
]
}
],
"source": [
"import requests\n",
"import re\n",
"# 发送POST请求进行登录\n",
"session = requests.Session()\n",
"url = 'https://print.f6yc.com/print-server/template/uploadTemplate'\n",
"\n",
"headers = {\n",
" 'Accept':'*/*',\n",
" 'Accept-Encoding':'gzip, deflate, br, zstd',\n",
" 'Accept-Language':'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7',\n",
" 'Authorization':'Basic NjAyMzg6Q3dAMzQwODI2',\n",
" 'Cache-Control':'no-cache',\n",
" 'Content-Length':'110826',\n",
" 'Content-Type':'multipart/form-data; boundary=----WebKitFormBoundaryPS5lcRsMTrbTlsm0',\n",
" 'Cookie':'print-serverSESSIONID=C4blK6XZ3R4cPoz8oME3-7zpVyryfbEqaCIrO7lK; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%222268275546837446%22%2C%22first_id%22%3A%221753edeb75a603-0155d23aa05675-3d634f03-1327104-1753edeb75b347%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%221753edeb75a603-0155d23aa05675-3d634f03-1327104-1753edeb75b347%22%7D; _yg_prod=EkX_f7K7eYt61spccZtpCE7FHwA2I5PROPsPCa8-iC3ASlLYfszIPQQqjcJjPPEZL0J2pO07cfpwVG-vQiXuF_g96wpnVRU7RGb1e5vW9kCewwIM05-hAXqyHZDn6PTH2oT4TDPMGRGOiijcH2MfVIFSNGm_aG9C3g..',\n",
" 'Origin':'https://print.f6yc.com',\n",
" 'Pragma':'no-cache',\n",
" 'Referer':'https://print.f6yc.com/print-server/ui/index.html',\n",
" 'Sec-Ch-Ua':'\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"',\n",
" 'Sec-Ch-Ua-Mobile':'?0',\n",
" 'Sec-Ch-Ua-Platform':'\"Windows\"',\n",
" 'Sec-Fetch-Dest':'empty',\n",
" 'Sec-Fetch-Mode':'cors',\n",
" 'Sec-Fetch-Site':'same-origin',\n",
" 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'\n",
"}\n",
"file_path = \"941b03aaa8f34d51a6811619c5402771.jasper\"\n",
"with open(file_path, \"rb\") as f:\n",
" files = {\"file\": (file_path, f)}\n",
" response = requests.post(url,headers=headers ,cookies=cookie_dict,files=files)\n",
"# response = session.post(url,headers=headers,files=files)\n",
"response.json()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: '941b03aaa8f34d51a6811619c5402771.jasper'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-3-d442676daa5d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 26\u001b[0m }\n\u001b[0;32m 27\u001b[0m \u001b[0mfile_path\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"941b03aaa8f34d51a6811619c5402771.jasper\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 28\u001b[1;33m \u001b[1;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_path\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"rb\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 29\u001b[0m \u001b[0mfiles\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;34m\"file\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mfile_path\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 30\u001b[0m \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpost\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mheaders\u001b[0m \u001b[1;33m,\u001b[0m\u001b[0mcookies\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcookie_dict\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mfiles\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfiles\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '941b03aaa8f34d51a6811619c5402771.jasper'"
]
}
],
"source": [
"import requests\n",
"import re\n",
"# 发送POST请求进行登录\n",
"session = requests.Session()\n",
"url = 'https://print.f6yc.com/print-server/template/uploadTemplate'\n",
"\n",
"headers = {\n",
" 'Accept':'*/*',\n",
" 'Accept-Encoding':'gzip, deflate, br, zstd',\n",
" 'Accept-Language':'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7',\n",
" 'Authorization':'Basic NjAyMzg6Q3dAMzQwODI2',\n",
" 'Cache-Control':'no-cache',\n",
" 'Content-Length':'110826',\n",
" 'Content-Type':'multipart/form-data; boundary=----WebKitFormBoundaryPS5lcRsMTrbTlsm0',\n",
" 'Cookie':'print-serverSESSIONID=XclmYVYrCTstT43MeO9X_4GrOAMfpcoaritzhGHN; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%222268275546837446%22%2C%22first_id%22%3A%221753edeb75a603-0155d23aa05675-3d634f03-1327104-1753edeb75b347%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%221753edeb75a603-0155d23aa05675-3d634f03-1327104-1753edeb75b347%22%7D',\n",
" 'Origin':'https://print.f6yc.com',\n",
" 'Pragma':'no-cache',\n",
" 'Referer':'https://print.f6yc.com/print-server/ui/index.html',\n",
" 'Sec-Ch-Ua':'\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"',\n",
" 'Sec-Ch-Ua-Mobile':'?0',\n",
" 'Sec-Ch-Ua-Platform':'\"Windows\"',\n",
" 'Sec-Fetch-Dest':'empty',\n",
" 'Sec-Fetch-Mode':'cors',\n",
" 'Sec-Fetch-Site':'same-origin',\n",
" 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'\n",
"}\n",
"file_path = \"941b03aaa8f34d51a6811619c5402771.jasper\"\n",
"with open(file_path, \"rb\") as f:\n",
" files = {\"file\": (file_path, f)}\n",
" response = requests.post(url,headers=headers ,cookies=cookie_dict,files=files)\n",
"\n",
"print(response.text)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'file': ('941b03aaa8f34d51a6811619c5402771.jasper',\n",
" <_io.BufferedReader name='941b03aaa8f34d51a6811619c5402771.jasper'>)}"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"files"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<html>\n",
"<head><title>401 Authorization Required</title></head>\n",
"<body>\n",
"<center><h1>401 Authorization Required</h1></center>\n",
"<hr><center>nginx</center>\n",
"</body>\n",
"</html>\n",
"\n"
]
}
],
"source": [
"print(response.text)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<bound method Response.json of <Response [200]>>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import requests\n",
"import re\n",
"# 发送POST请求进行登录\n",
"session = requests.Session()\n",
"login_url = 'https://print.f6yc.com/print-server/template/getTemplate?clsId=&tempCode=&tempName=&currentPage=1&pageSize=10'\n",
"\n",
"headers = {\n",
" 'Accept':'application/json, text/plain, */*',\n",
" 'Accept-Encoding':'gzip, deflate, br, zstd',\n",
" 'Accept-Language':'zh-CN,zh;q=0.9',\n",
" 'Authorization':'Basic NjAyMzg6Q3dAMzQwODI2',\n",
" 'Cache-Control':'no-cache',\n",
" 'Cookie':'print-serverSESSIONID=XclmYVYrCTstT43MeO9X_4GrOAMfpcoaritzhGHN; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%222268275546837446%22%2C%22first_id%22%3A%221753edeb75a603-0155d23aa05675-3d634f03-1327104-1753edeb75b347%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22%24device_id%22%3A%221753edeb75a603-0155d23aa05675-3d634f03-1327104-1753edeb75b347%22%7D',\n",
" 'Pragma':'no-cache',\n",
" 'Referer':'https://print.f6yc.com/print-server/ui/index.html',\n",
" 'Sec-Ch-Ua':'\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"',\n",
" 'Sec-Ch-Ua-Mobile':'?0',\n",
" 'Sec-Ch-Ua-Platform':'\"Windows\"',\n",
" 'Sec-Fetch-Dest':'empty',\n",
" 'Sec-Fetch-Mode':'cors',\n",
" 'Sec-Fetch-Site':'same-origin',\n",
" 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'\n",
"}\n",
"\n",
"response = session.get(login_url,headers=headers)\n",
"response.json"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Response [200]>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"response"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "F6processing",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}