<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Monterey &#8211; 李辉 / Grey Li</title>
	<atom:link href="https://greyli.com/tag/monterey/feed/" rel="self" type="application/rss+xml" />
	<link>https://greyli.com</link>
	<description>一个编程和写作爱好者的在线记事本</description>
	<lastBuildDate>Thu, 06 Nov 2025 11:36:11 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.9.26</generator>

<image>
	<url>https://greyli.com/wp-content/uploads/2025/03/avatar-500-compressed-144x144.jpg</url>
	<title>Monterey &#8211; 李辉 / Grey Li</title>
	<link>https://greyli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>如果你在 macOS 上无法访问 Flask 程序</title>
		<link>https://greyli.com/thank-you-apple/</link>
		<comments>https://greyli.com/thank-you-apple/#respond</comments>
		<pubDate>Sun, 03 Apr 2022 09:37:51 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[Monterey]]></category>
		<category><![CDATA[ngrok]]></category>

		<guid isPermaLink="false">https://greyli.com/?p=4298</guid>
		<description><![CDATA[如果你用 macOS 开发 Flask 时无法正常访问程序，或是使用 ngrok 等内网穿透工具时映射的公网地 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>如果你用 macOS 开发 Flask 时无法正常访问程序，或是使用 <a href="https://greyli.com/use-ngrok-to-expose-your-local-application/">ngrok</a> 等内网穿透工具时映射的公网地址无法访问，大概率是因为 macOS 新版本（Monterey）的变动导致。你会在页面上看到类似下面的错误信息：</p>
<pre>Access to 127.0.0.1 was denied.

You don't have authorization to view this page.

HTTP ERROR 403</pre>
<p>或是在执行 flask run 命令时看到类似下面的报错：</p>
<pre>OSError: [Errno 48] Address already in use</pre>
<p>首先确认你的 macOS 版本是不是 Monterey（左上角 Apple 图标 &#8211; About This Mac）或是之后的版本，如果不是那么问题应该和本文无关。</p>
<p>简单来说，新版本的 macOS 上 localhost 5000 端口被一个叫 AirPlay Receiver 的服务占用了。而 Flask 内置服务器默认就运行在 5000 端口，所以会造成端口冲突。当你通过将 host 设为 0.0.0.0 指定 Flask 的内置服务器对外可见，或是使用内网穿透工具时，会发现程序无法访问（有时未设置对外可见也会遇到这个问题）。</p>
<p>最简单的解决方法是关掉这个服务：</p>
<ul>
<li>系统设置（System Preferences） &gt; 分享（Sharing） &gt; AirPlay Receiver &gt; 取消勾选</li>
</ul>
<p>或是更改 Flask 开发服务器默认的端口（比如改成 8000）。在执行 flask run 命令时使用 -p/&#8211;port 选项可以自定义端口：</p>
<pre>$ flask run -p 8000  # 或 flask run --port 8000</pre>
<p>或是在执行 flask run 之前通过环境变量 FLASK_RUN_PORT 设置：</p>
<pre>$ export FLASK_RUN_PORT=8000 # macOS/Linux
&gt; set FLASK_RUN_PORT=8000 # Windows CMD
&gt; $env:FLASK_RUN_PORT=8000 # Powershell</pre>
<p>在 Werkzueg 2.1.0（2022/3/28 发布）版本，如果你执行 flask run &#8211;host=0.0.0.0 时检测到了端口被占用，会直接显示相关的错误提示：</p>
<pre>$ flask run --host=0.0.0.0
Address already in use
Port 5000 is in use by another program. Either identify and stop that program, or start the server with a different port.
On macOS, try disabling the 'AirPlay Receiver' service from System Preferences -&gt; Sharing.</pre>
<p>本文源于去年十一月发的<a href="https://twitter.com/greylihui/status/1455392110618857474">一条推文</a>，最近经常碰见有人遇到这个问题，所以转成这篇文章发出来。</p>
<p>画了一幅涂鸦，送给苹果公司：</p>
<p><a href="https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000.png"><img class="aligncenter size-full wp-image-4310" src="https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000.png" alt="" width="816" height="566" srcset="https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000.png 816w, https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000-150x104.png 150w, https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000-300x208.png 300w, https://greyli.com/wp-content/uploads/2022/04/apple-eat-port5000-624x433.png 624w" sizes="(max-width: 816px) 100vw, 816px" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/thank-you-apple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
