ollama.pull() fails with ResponseError but `ollama pull` on the command line works fine
I have a basic Ollama service running on 127.0.0.1:11434 as default, and I am trying to use the model "mistral-small:24b-instruct-2501-q4_K_M".
When trying to use the python library to
ollama.pull("mistral-small:24b-instruct-2501-q4_K_M")
I get a ResponseError:
Cell In[3], line 1
----> 1 ollama.pull("mistral-small:24b-instruct-2501-q4_K_M")
File /env/lib/python3.10/site-packages/ollama/_client.py:422, in Client.pull(self, model, insecure, stream)
410 def pull(
411 self,
412 model: str,
(...)
415 stream: bool = False,
416 ) -> Union[ProgressResponse, Iterator[ProgressResponse]]:
417 """
418 Raises `ResponseError` if the request could not be fulfilled.
419
420 Returns `ProgressResponse` if `stream` is `False`, otherwise returns a `ProgressResponse` generator.
421 """
--> 422 return self._request(
423 ProgressResponse,
424 'POST',
425 '/api/pull',
426 json=PullRequest(
427 model=model,
428 insecure=insecure,
429 stream=stream,
430 ).model_dump(exclude_none=True),
431 stream=stream,
432 )
File /data/rg_data/pct_mai/Users/Anandamoy/anaconda3/envs/unsloth_env/lib/python3.10/site-packages/ollama/_client.py:178, in Client._request(self, cls, stream, *args, **kwargs)
174 yield cls(**part)
176 return inner()
--> 178 return cls(**self._request_raw(*args, **kwargs).json())
File /data/rg_data/pct_mai/Users/Anandamoy/anaconda3/envs/unsloth_env/lib/python3.10/site-packages/ollama/_client.py:122, in Client._request_raw(self, *args, **kwargs)
120 return r
121 except httpx.HTTPStatusError as e:
--> 122 raise ResponseError(e.response.text, e.response.status_code) from None
123 except httpx.ConnectError:
124 raise ConnectionError(CONNECTION_ERROR_MESSAGE) from None
ResponseError: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta type="copyright" content="Copyright (C) 1996-2016 The Squid Software Foundation and contributors">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ERROR: The requested URL could not be retrieved</title>
<style type="text/css"><!--
/*
* Copyright (C) 1996-2016 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
* Please see the COPYING and CONTRIBUTORS files for details.
*/
/*
Stylesheet for Squid Error pages
Adapted from design by Free CSS Templates
http://www.freecsstemplates.org/
Released for free under a Creative Commons Attribution 2.5 License
*/
/* Page basics */
* {
font-family: verdana, sans-serif;
}
html body {
margin: 0;
padding: 0;
background: #efefef;
font-size: 12px;
color: #1e1e1e;
}
/* Page displayed title area */
#titles {
margin-left: 15px;
padding: 10px;
padding-left: 100px;
background: url('/squid-internal-static/icons/SN.png') no-repeat left;
}
/* initial title */
#titles h1 {
color: #000000;
}
#titles h2 {
color: #000000;
}
/* special event: FTP success page titles */
#titles ftpsuccess {
background-color:#00ff00;
width:100%;
}
/* Page displayed body content area */
#content {
padding: 10px;
background: #ffffff;
}
/* General text */
p {
}
/* error brief description */
#error p {
}
/* some data which may have caused the problem */
#data {
}
/* the error message received from the system or other software */
#sysmsg {
}
pre {
font-family:sans-serif;
}
/* special event: FTP directory listing */
#dirmsg {
font-family: courier;
color: black;
font-size: 10pt;
}
#dirlisting {
margin-left: 2%;
margin-right: 2%;
}
#dirlisting tr.entry td.icon,td.filename,td.size,td.date {
border-bottom: groove;
}
#dirlisting td.size {
width: 50px;
text-align: right;
padding-right: 5px;
}
/* horizontal lines */
hr {
margin: 0;
}
/* page displayed footer area */
#footer {
font-size: 9px;
padding-left: 10px;
}
body
:lang(fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-serif; float: right; }
:lang(he) { direction: rtl; }
--></style>
</head><body id=ERR_ACCESS_DENIED>
<div id="titles">
<h1>ERROR</h1>
<h2>The requested URL could not be retrieved</h2>
</div>
<hr>
<div id="content">
<p>The following error was encountered while trying to retrieve the URL: <a href="http://127.0.0.1:11434/api/pull">[http://127.0.0.1:11434/api/pull</a></p](http://127.0.0.1:11434/api/pull%3C/a%3E%3C/p)>
<blockquote id="error">
<p><b>Access Denied.</b></p>
</blockquote>
<p>Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.</p>
<p>Your cache administrator is <a href="mailto:root?subject=CacheErrorInfo%20-%20ERR_ACCESS_DENIED&body=CacheHost%3A%20proxy.ec2.internal%0D%0AErrPage%3A%20ERR_ACCESS_DENIED%0D%0AErr%3A%20%5Bnone%5D%0D%0ATimeStamp%3A%20Thu,%2006%20Feb%202025%2019%3A34%3A27%20GMT%0D%0A%0D%0AClientIP%3A%20192.168.12.105%0D%0A%0D%0AHTTP%20Request%3A%0D%0APOST%20%2Fapi%2Fpull%20HTTP%2F1.1%0AAccept-Encoding%3A%20gzip,%20deflate%0D%0AConnection%3A%20keep-alive%0D%0AContent-Type%3A%20application%2Fjson%0D%0AAccept%3A%20application%2Fjson%0D%0AUser-Agent%3A%20ollama-python%2F0.4.7%20(x86_64%20linux)%20Python%2F3.10.12%0D%0AContent-Length%3A%2087%0D%0AHost%3A%20127.0.0.1%3A11434%0D%0A%0D%0A%0D%0A">root</a>.</p>
<br>
</div>
<hr>
<div id="footer">
<p>Generated Thu, 06 Feb 2025 19:34:27 GMT by proxy.ec2.internal (squid/3.5.20)</p>
<!-- ERR_ACCESS_DENIED -->
</div>
</body></html>
(status code: 403)
However, when I try ollama pull mistral-small:24b-instruct-2501-q4_K_M from the command line it works as expected, pulling the model files. Why is it working from the CLI but fails from the python library?
Am I doing something wrong? New to Ollama, so any help will be much appreciated.
When you say it works from the command line - is the cURL request working? Something like:
curl http://localhost:11434/api/pull -d '{
"model": "llama3.2"
}'
Trying to see if this is a python issue or network - I'm pretty sure it's network related given the result you got back.
I am getting the same error. I can chat with the model through CLI by running ollama run <MODEL>. However, when I try to connect with API, I am getting the same HTML error file.