Pycharm is unable to connect to jupyter with connection refused, while browsers are able to connect
Pycharm is not able to connect to jupyter notebook (connection refused) while accessing it via a browser is perfectly fine. The pycharm logs gave the following:
2019-10-16 17:07:20,039 [ 310024] ERROR - ctions.ui.JupyterErrorReporter - Unhandled Jupyter error
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8888 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.apache.http.client.fluent.Request.internalExecute(Request.java:173)
at org.apache.http.client.fluent.Executor.execute(Executor.java:262)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.JupyterRestClient.executeAndCheck(JupyterRestClient.kt:173)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.JupyterRestClient.get(JupyterRestClient.kt:150)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.JupyterRestClient.getKernelSpecs(JupyterRestClient.kt:88)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.core.JupyterClientImpl.getKernelSpecs(JupyterClient.kt:65)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.core.JupyterServerImpl.updateKernelSpecs(JupyterServers.kt:127)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.JupyterRuntimeServiceImpl.createSession(JupyterNotebookExecution.kt:209)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.JupyterRuntimeServiceImpl.createManagedServerSessionSettings(JupyterNotebookExecution.kt:196)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.JupyterRuntimeServiceImpl.createManagedServerSessionSettings$default(JupyterNotebookExecution.kt:188)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.JupyterRuntimeServiceImpl.getOrCreateSession(JupyterNotebookExecution.kt:106)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.JupyterCellExecutionManager.executeCode(JupyterCellExecutionManager.kt:113)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.JupyterCellExecutionManager.access$executeCode(JupyterCellExecutionManager.kt:39)
at org.jetbrains.plugins.notebooks.jupyter.connections.execution.JupyterCellExecutionManager$executeCode$$inlined$synchronized$lambda$1.run(JupyterCellExecutionManager.kt:80)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
... 28 more
2019-10-16 17:07:20,040 [ 310025] ERROR - ctions.ui.JupyterErrorReporter - PyCharm 2019.2.3 Build #PY-192.6817.19
2019-10-16 17:07:20,040 [ 310025] ERROR - ctions.ui.JupyterErrorReporter - JDK: 11.0.4; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o
2019-10-16 17:07:20,041 [ 310026] ERROR - ctions.ui.JupyterErrorReporter - OS: Linux
Please sign in to leave a comment.
Hi!
Is it a Managed Jupyter server or Configured Server? (File | Settings | Build, Execution, Deployment | Jupyter | Jupyter Server)
Is it password-protected?
HI Sergey,
It is a managed server, and it is not password protected. I am able to access the exact same server just fine in chrome, that's what I don't understand.
It's strange that PyCharm can start the server but cannot connect to it.
Please try the following and let me know the result:
1) Start jupyter server from the system terminal (outside of PyCharm).
2) Configure that server in PyCharm as Configured Server and try running the cell.
Does it work?
Same thing, I can access it from a browser, but pycharm can't. I did find out that I also cannot access the 127.0.0.1:8888 url of jupyter from the browser, but I can access the localhost:8888 url.
Looks like something is blocking PyCharm and it can't connect to the server.
Does debugger work with some *.py files?
The debugger seems to work, or is there a specific way you want me to check it?
I fixed it. My hosts file had a erroneous "\" at one of the entries and thus the localhost to 127.0.0.1 resolve errored. Thanks!
Oh, I see, thank you for letting me know!
Glad to hear that it works fine now.