微信查询medicaid时出现503错误码?

Got 503 error code while retrieveing mediaid in wechat?

API http://admin.wechat.com/wiki/index.php?title=Transferring_Multimedia_Files

import requests
r='https://api.wechat.com/cgi-bin/token?grant_type=client_credential&appid=wx82c6ebdb6e33ad33&secret=c2861ec348b3c94087c4b64cbe166fbb' #credentials sharing no problem
a=(requests.get(r).json()['access_token'])
print(a)
params = (
    ('access_token', a),
    ('type', 'image'),
)

import os
files = {
    'media': ('1.jpg', open('static/1.jpg', 'rb'),'image/jpg',),
}
print()
response = requests.post('http://file.api.wechat.com/cgi-bin/media/upload', params=params, files=files)

def uprint(x,file=None):
  try:
    pass
    if x:
      print(x.encode('cp65001',errors='backslashreplace').decode('cp1252'),file=file)
  except Exception as e:
    return f'{x}\n{e}'
def prin(*a):print(ascii(*a))    
print(response.text,file=open('z.html','a',encoding="utf-8"))
print(response.headers)

看起来您正在使用 http 进行上传调用。我以前看到过由于这个原因从网站返回的这个错误。

HTTP 错误 503 表示 "Service Unavailable"。通常是由于服务器临时过载或维护而无法处理请求时由服务器返回。

检查 API documentation for wechat 后,我注意到了这一点:

  1. This API must be used via HTTPS.

然后我在 the Q&A 中注意到了这一点:

Q: Which server should I send API requests to?

A: If you have an International Official Account, use api.wechat.com.

If you have a China Official Account, use api.weixin.qq.com.

因此,在您的情况下,我认为您需要使用 https 和域 api.wechat.com,如下所示:

response = requests.post('https://api.wechat.com/cgi-bin/media/upload', params=params, files=files)