PythonコードでのPOSTに関する問題

トピック作成者:ks-solruserml-bot (2025/03/01 22:58 投稿)
3
(The bot translated the original post https://lists.apache.org/thread/47g92m8qvlnk18hr5c8r5dq9n0co3f3c into Japanese and reposted it under Apache License 2.0. The copyright of posted content is held by the original poster.)
こんにちは
PythonのPOSTメソッドを使用してSOLRサーバーに接続しようとしていますが、エラーが発生しています。
以下がコードです(完全なファイルは添付されています):
# URLを作成
searchURL = 'http://localhost:8983/solr/films/query'
querytext = {"json":{"query":"shane"}}
#querytext = {"query":"*:*"}
# クエリを作成
query = urllib.parse.urlencode(querytext).encode('utf-8')
# サーバーからデータを取得
try:
connection = urllib.request.Request(searchURL, query)
except Exception as error:
print("接続失敗: ", error)
exit()
connection.add_header('Content-Type', 'application/json')
# 接続からデータを取得
try:
response = urllib.request.urlopen(connection)
except Exception as error:
print("レスポンスが返されませんでした: ", error)
exit()
レスポンスは以下の通りです:
solr-9.6.1>python python-appsilm-POST.py
レスポンスが返されませんでした: HTTP Error 400: Bad Request
サーバーのログには以下のように記録されています:
(画像の内容省略)
この問題を解決するためにさまざまな方法を試しましたが、成功しませんでした。
どなたか助けていただけますか?
よろしくお願いします。
Andy
トピックへ返信するには、ログインが必要です。