1

I tried to request local model by using Python with below code,

import requests
import json

url = 'http://localhost:1234/v1/chat/completions'

headers = {
    'Content-Type': 'application/json'
}

data = {
    'model': 'deepseek-r1-distill-qwen-7b',
    'messages': [
        {'role': 'system', 'content': 'Always answer in rhymes. Today is Thursday'},
        {'role': 'user', 'content': 'What day is it today?'}
    ],
    'temperature': 0.7,
    'max_tokens': -1,
    'stream': False
}

response = requests.post(url, headers=headers, data=json.dumps(data))

if response.status_code == 200:
    print('Response:', response.json())
else:
    print('Error:', response.status_code, response.text)

and got 503 service unavailable error. But if I request it successfully via Curl,

curl http://localhost:1234/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-r1-distill-qwen-7b",
    "messages": [
      { "role": "system", "content": "Always answer in rhymes. Today is Thursday" },
      { "role": "user", "content": "What day is it today?" }
    ],
    "temperature": 0.7,
    "max_tokens": -1,
    "stream": false
}'

why this happening and how could I fix it?

1 Answer 1

0

The REQUESTS may be using a system proxy, curl and python.requests operate differently

session = requests.Session()
session.trust_env = False
response = session.post(...)

Also I'd recommend to try request it using tools like Postman or Insomnia, then check the request/response headers, probably LM server sets required headers, or try to set "Content-Length":

data_str = json.dumps(data)
headers["Content-Length"] = str(len(data_str))

You may also try to export the Python Requests code from Postman and check the difference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.