You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacBook M4 Max本地Ollama无法被Python脚本连接的ETL任务故障求助

MacBook M4 Max本地Ollama无法被Python脚本连接的ETL任务故障求助

我正在基于LLM搭建一套ETL流程,用来提取广告文本里的用户信息。我的环境是MacBook M4 Max,本地已经安装了Ollama,但运行worker进程的时候一直遇到连接错误,导致任务失败,实在找不到问题所在,来这里求助!

故障日志

ads-worker-1 | 2025-08-28 15:05:54,983 - INFO - Got the db connection: <connection object at 0xffff76241300; dsn: 'user=wtat_user password=xxx dbname=wtat_db host=postgres port=5432 options='-c search_path=wtat'', closed: 0>
ads-worker-1 | 2025-08-28 15:05:54,986 - INFO - Marked the extraction from 83e9b92b-9bc7-4b7e-bf95-d511c239cf79 PENDING
ads-worker-1 | 2025-08-28 15:05:54,986 - INFO - Extract profiles from ads #1
ads-worker-1 | 2025-08-28 15:05:54,986 - INFO - [{'ad_id': '83e9b92b-9bc7-4b7e-bf95-d511c239cf79', 'publication_date': '2021-12-26 00:00:00', 'publication_text': "DJO 1\nSalut le terre. Suis un homme de 35ans, originaire de l’Ouest Cameroun, sans enfants et résident au Canada. J'ai 1.85m pour 85kg. Suis étudiant en génie mais avec un emploi stable. Mes proches me décrivent comme quelqu'un d'attentionné, calme, travailleur et responsable. Suis a la recherche d'une femme (max 31ans),respectueuse, honnête et sérieuse (car trop de jongleuses de nos jours); résident au Canada et de préférence sans enfants. Celles qui se sentent concernées et prêtent à fonder une famille, pouvez m'écrire à cette adresse mail: durableamour237@gmail.com Merci.", 'publication_type': 'Dimanche'}]
ads-worker-1 | 2025-08-28 15:05:54,986 - INFO - Pas de batching pour Ollama
ads-worker-1 | 2025-08-28 15:05:54,986 - INFO - DEBUG: type(ads)=<class 'list'>, len(ads)=1
ads-worker-1 | 2025-08-28 15:05:55,183 - INFO - Retrying request to /chat/completions in 0.491779 seconds
ads-worker-1 | 2025-08-28 15:05:55,804 - INFO - Retrying request to /chat/completions in 0.964398 seconds
ads-worker-1 | 2025-08-28 15:05:56,921 - ERROR - LLM error for ad 83e9b92b-9bc7-4b7e-bf95-d511c239cf79:
ads-worker-1 | Connection error. from Extract Profiles
ads-worker-1 | 2025-08-28 15:05:56,922 - INFO - Processed batch: 1 ads, 1 results
ads-worker-1 | 2025-08-28 15:05:56,922 - INFO - Process single ad result with error handling: 83e9b92b-9bc7-4b7e-bf95-d511c239cf79
ads-worker-1 | 2025-08-28 15:05:56,923 - ERROR - Failed to process ad 83e9b92b-9bc7-4b7e-bf95-d511c239cf79: Missing required profile data
ads-worker-1 | 2025-08-28 15:05:56,928 - INFO - Ad 83e9b92b-9bc7-4b7e-bf95-d511c239cf79: Marked as failed
ads-worker-1 | 2025-08-28 15:05:56,932 - INFO - Method frame: <Basic.GetOk(['delivery_tag=2', 'exchange=', 'message_count=8', 'redelivered=False', 'routing_key=ads'])>. Batch: 0
ads-worker-1 | 2025-08-28 15:05:56,932 - INFO - Process batch with acknowledgment handling: 1
ads-worker-1 | 2025-08-28 15:05:56,932 - INFO - Process batch with transaction management: 1
ads-worker-1 | 2025-08-28 15:05:56,937 - INFO - Got the db connection: <connection object at 0xffff76241300; dsn: 'user=wtat_user password=xxx dbname=wtat_db host=postgres port=5432 options='-c search_path=wtat'', closed: 0>
ads-worker-1 | 2025-08-28 15:05:56,937 - INFO - Marked the extraction from 0e07c075-14b4-400c-9917-6b592c913082 PENDING
ads-worker-1 | 2025-08-28 15:05:56,938 - INFO - Extract profiles from ads #1
ads-worker-1 | 2025-08-28 15:05:56,938 - INFO - [{'ad_id': '0e07c075-14b4-400c-9917-6b592c913082', 'publication_date': '2021-12-26 00:00:00', 'publication_text': "RESSE 2\nSalut à tous! Je suis une camerounaise de 33 ans, maman de 2 enfans ,vivant en Angleterre. Je suis une femme posée et calme.\xa0 Je fais 1.62m pour 60 kg. Je recherche un homme\xa0 attentionné, aimable, honnête\xa0 et prêt à s'engager pour une\xa0 relation sincère et durable, âgé\xa0 entre 34 et 45 ans avec ou sans enfants,\xa0 vivant en Angleterre ou ailleurs. Si interressé merçi\xa0 de me joindre à cette addresse: sincerelove2021@yahoo.com", 'publication_type': 'Dimanche'}]
ads-worker-1 | 2025-08-28 15:05:56,938 - INFO - Pas de batching pour Ollama
ads-worker-1 | 2025-08-28 15:05:56,938 - INFO - DEBUG: type(ads)=<class 'list'>, len(ads)=1
ads-worker-1 | 2025-08-28 15:05:57,082 - INFO - Retrying request to /chat/completions in 0.413912 seconds
ads-worker-1 | 2025-08-28 15:05:57,651 - INFO - Retrying request to /chat/completions in 0.876515 seconds
ads-worker-1 | 2025-08-28 15:05:58,660 - ERROR - LLM error for ad 0e07c075-14b4-400c-9917-6b592c913082:
ads-worker-1 | Connection error. from Extract Profiles
ads-worker-1 | 2025-08-28 15:05:58,660 - INFO - Processed batch: 1 ads, 1 results
ads-worker-1 | 2025-08-28 15:05:58,660 - INFO - Process single ad result with error handling: 0e07c075-14b4-400c-9917-6b592c913082
ads-worker-1 | 2025-08-28 15:05:58,662 - ERROR - Failed to process ad 0e07c075-14b4-400c-9917-6b592c913082: Missing required profile data
ads-worker-1 | 2025-08-28 15:05:58,667 - INFO - Ad 0e07c075-14b4-400c-9917-6b592c913082: Marked as failed
ads-worker-1 | 2025-08-28 15:05:58,669 - INFO - Method frame: <Basic.GetOk(['delivery_tag=3', 'exchange=', 'message_count=7', 'redelivered=False', 'routing_key=ads'])>

我已经做的排查

  • 确认PostgreSQL数据库连接正常(日志里显示连接成功)
  • 检查过worker脚本的逻辑,广告数据能正常读取
  • 本地Ollama已经安装,之前单独用ollama run测试过模型能正常响应

疑问&求助点

从日志里能看到脚本一直在重试请求Ollama的/chat/completions接口,但每次都失败报连接错误,进而导致提取不到数据任务失败。想请教大家:

  • 有没有可能是M4 Max的系统设置(比如防火墙、隐私权限)阻止了脚本访问本地Ollama端口?
  • 脚本里的Ollama API地址应该怎么配置才对?我用的是默认的http://localhost:11434/v1,会不会有问题?
  • 还有哪些我没考虑到的排查方向?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 03:10:42