PrintBase
  • Product
  • Pricing
  • Docs
  • Resources
PrintBase/专题/打印排障

打印组件连接失败和端口冲突

本地打印组件互相占用端口时,表现为连接失败。PrintBase 的云端接口不使用那些组件端口。Agent 可选的本地端口是 127.0.0.1:17891。调用 POST /v1/print-jobs,API Key 只放在服务端。

面向 电脑上装了多个电商打印组件的人

说明

菜鸟、抖店、拼多多等组件常在本机监听自己的端口。两个程序抢同一个端口时,后启动的会连接失败。本页故意不写死端口号,因为各组件版本会变,以你机器上实际监听的端口为准。打印机由门店电脑上的 Agent 主动连出,不需要公网 IP,也不需要把 9100 端口映射到互联网。

PrintBase 的主路径不经过这些组件。服务器调用 HTTPS 接口,Agent 使用系统打印机。可选的本地调试端口是 127.0.0.1:17891,并且只接受限定来源。它不是电商组件的端口。

若某个组件独占了标签机驱动,Agent 也会打印失败。那是设备被占用,不是端口号本身。测试时先退出不用的组件。

创建任务使用 POST /v1/print-jobs,请求头 Authorization: Bearer,正文包含 printer_code、content_type(pdf 或 raw)以及 content 或 content_url 二者之一。免费套餐是一台电脑每月 100 个任务。

创建任务使用 POST /v1/print-jobs,请求头 Authorization: Bearer,正文包含 printer_code、content_type(pdf 或 raw)以及 content 或 content_url 二者之一。免费套餐是一台电脑每月 100 个任务。

接入步骤

  1. 01

    看是谁在报连接失败

    组件自己的界面失败,和 PrintBase 任务的 PRINT_ERROR 不是同一条日志。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

  2. 02

    确认云端任务是否创建

    有 job id 就说明没走组件端口。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

  3. 03

    退出不用的本地组件后再试

    避免独占驱动。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

  4. 04

    不要把 17891 暴露到局域网

    这个监听只应留在本机。请求使用 POST /v1/print-jobs,请求头为 Authorization: Bearer,printer_code 来自 GET /v1/printers。

Node.js

// 不经过本地组件的云端任务
const res = await fetch('https://api.printbase.cloud/v1/print-jobs', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.PRINTBASE_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': idempotencyKey,
  },
  body: JSON.stringify({
    printer_code: Number(process.env.PRINTER_CODE),
    content_type: 'pdf',
    content: pdf.toString('base64'),
    copies: 1,
  }),
});
if (!res.ok) throw new Error(`PrintBase ${res.status}: ${await res.text()}`);
const job = await res.json();
// { id: "job_abc", status: "queued" }

这一套的细节

17891

本地网页打印的默认地址。来源不允许时返回 403,不是端口冲突。Agent 只打印你提交的内容,不会替你向平台拉取单据。Agent 只打印你提交的内容,不会替你向平台拉取单据。

9100

斑马 Browser Print 的文档使用 9100/9101。那不是 PrintBase Agent 的端口。Agent 只打印你提交的内容,不会替你向平台拉取单据。

常见问题

要打开路由器端口吗?(详见本页)

不要。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

组件和 Agent 能一起装吗?

能。不要让它们抢同一台打印机的独占访问。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

连接失败但测试页正常?(详见本页)

系统驱动是好的。失败的是组件到本机端口的连接。改走 API 就可以不依赖那个端口。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

17891 被占用?(详见本页)

换掉占用它的程序,或暂时不用本地端口,只走云端接口。调用的仍是 POST /v1/print-jobs,请求头为 Bearer API Key。HTTP 201 只表示已排队,不表示已经出纸。

相关页面

  • 自建系统打印面单,不经过菜鸟组件

    菜鸟打印组件是给菜鸟面单准备的本地程序。你自己生成的 PDF 面单可以由 Agent 打印,它不代替菜鸟组件去解开菜鸟报文。调用 POST /v1/print-jobs,API Key 只放在服务端。

  • 网页静默打印:不弹预览的做法

    浏览器不会让公网页静默选打印机。可行的做法是服务器调用打印接口,而不是藏起 window.print。调用 POST /v1/print-jobs,API Key 只放在服务端。

  • 接口返回成功但没有出纸

    创建任务返回 201 只表示已排队。要看任务是否变成 completed。免费套餐用轮询,Webhook 在付费套餐。调用 POST /v1/print-jobs,API Key 只放在服务端。

免费套餐:一台电脑每月 100 个任务,不需要信用卡。

免费注册查看 API 文档
PrintBase

PrintBase connects your applications to physical printers anywhere - securely, reliably, and in real time.

Product
Receipt PrintingLabel PrintingDashboardDevicesWebhooks
Resources
DocsBlogStatusAPI ReferenceDownloadPrintBase vs PrintNodePrintNode PricingFAQ
Guides
All guidesIntegrationsPrintersCode samplesComparisonsUse casesTroubleshooting
Company
ContactSecurityPrivacy

© 2026 Aveniq Technologies OÜ. All rights reserved. PrintBase is a service of Aveniq Technologies OÜ.

PrivacyTermsRefunds