pyrebase.storage() - 无效的 HTTP method/URL 对
pyrebase.storage() - Invalid HTTP method/URL pair
我有一个脚本,我尝试使用 pyrebase
将图像上传到 firebse 的存储,为此我使用了 storage
函数,但它不起作用并抛出以下错误
Traceback (most recent call last):
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrebase\pyrebase.py", line 444, in raise_detailed_error
request_object.raise_for_status()
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://firebasestorage.googleapis.com/v0/b/gs://test-bc3ec.appspot.com//o?name=example.PNG
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Angel\Documents\respaldo\pyrebase_1..py", line 24, in <module>
storage.child("/example.PNG").put("Captura.PNG")
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrebase\pyrebase.py", line 406, in put
raise_detailed_error(request_object)
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrebase\pyrebase.py", line 448, in raise_detailed_error
raise HTTPError(e, request_object.text)
requests.exceptions.HTTPError: [Errno 400 Client Error: Bad Request for url: https://firebasestorage.googleapis.com/v0/b/gs://test-bc3ec.appspot.com//o?name=example.PNG] {
"error": {
"code": 400,
"message": "Invalid HTTP method/URL pair."
}
}
[Finished in 2.4s with exit code 1]
[shell_cmd: python -u "C:\Users\Angel\Documents\respaldo\pyrebase_1..py"]
[dir: C:\Users\Angel\Documents\respaldo]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\Angel\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\Angel\AppData\Local\Programs\Python\Python36\;C:\Users\Angel\Videos\flutter\bin;C:\Users\Angel\AppData\Local\Programs\Microsoft VS Code\bin]
这是代码:
import pyrebase
config = {
"apiKey":"AIzaSyDphkVRuW39CyUbLmT5OkeZ2YmAUhwEUm4",
"authDomain":"test-bc3ec",
"databaseURL":"https://test-bc3ec.firebaseio.com/",
"storageBucket":"gs://test-bc3ec.appspot.com/"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
uder = db.child("Nuevo").get()
print(uder.val())
#def stream_handler(message):
# print(message['path'])
# print(message['data'])
#myStream = db.child('Nuevo').stream(stream_handler)
storage = firebase.storage()
myfile = open("Captura.PNG","rb")
bytesm = myfile.read()
fbupload = storage.child("/test/").put(bytesm)
也试试 firebase_admin
import firebase_admin
from firebase_admin import credentials,db,storage
cred = credentials.Certificate("nuevo.json")
firebase_admin.initialize_app(cred,{
'databaseURL':'https://test-bc3ec.firebaseio.com/'
})
s = firebase_admin.storage()
s.child("imagenes/Captura.PNG").put("Captura.PNG")
此代码错误:
Traceback (most recent call last):
File "C:\Users\Angel\Documents\respaldo\firebase_ad.py", line 13, in <module>
s = firebase_admin.storage()
TypeError: 'module' object is not callable
[Finished in 0.8s]
但是也不行
pyrebase 第二
storage = firebase.storage()
myfile = open("Captura.PNG","rb")
bytesm = myfile.read()
fbupload = storage.child("/test/Captura.png").put(bytesm)
Question: Invalid HTTP method/URL pair
config["storageBucket"]
使用您的config
:
"storageBucket":"gs://test-bc3ec.appspot.com/"
Output:
I get Invalid HTTP method/URL pair.
"error": {
"code": 400,
"message": "Invalid HTTP method/URL pair."
}
改为
注意:删除了前导 gs://
和尾随 /
。
"storageBucket":"test-bc3ec.appspot.com"
Output:
I get Permissin denied
instead of Invalid HTTP method/URL pair
,
as i can't auth against test-bc3ec
"error": {
"code": 403,
"message": "Permission denied. Could not perform this operation"
}
-
put
The put method takes the path to the local file and an optional user token.
storage = firebase.storage()
# as admin
storage.child("images/example.jpg").put("example2.jpg")
# as user
storage.child("images/example.jpg").put("example2.jpg", user['idToken'])
你的storage
注:"test"
不带前导/
。
storage = firebase.storage()
local_file_path = "Captura.PNG"
storage_file_path = "test/Captura.PNG"
fbupload = storage.child(storage_file_path).put(local_file_path)
请报告第 3 步,因为我无法验证这一点。
测试 Python:3.4.2 - Pyrebase:3.0.27
我有一个脚本,我尝试使用 pyrebase
将图像上传到 firebse 的存储,为此我使用了 storage
函数,但它不起作用并抛出以下错误
Traceback (most recent call last):
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrebase\pyrebase.py", line 444, in raise_detailed_error
request_object.raise_for_status()
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://firebasestorage.googleapis.com/v0/b/gs://test-bc3ec.appspot.com//o?name=example.PNG
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Angel\Documents\respaldo\pyrebase_1..py", line 24, in <module>
storage.child("/example.PNG").put("Captura.PNG")
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrebase\pyrebase.py", line 406, in put
raise_detailed_error(request_object)
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrebase\pyrebase.py", line 448, in raise_detailed_error
raise HTTPError(e, request_object.text)
requests.exceptions.HTTPError: [Errno 400 Client Error: Bad Request for url: https://firebasestorage.googleapis.com/v0/b/gs://test-bc3ec.appspot.com//o?name=example.PNG] {
"error": {
"code": 400,
"message": "Invalid HTTP method/URL pair."
}
}
[Finished in 2.4s with exit code 1]
[shell_cmd: python -u "C:\Users\Angel\Documents\respaldo\pyrebase_1..py"]
[dir: C:\Users\Angel\Documents\respaldo]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\Angel\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\Angel\AppData\Local\Programs\Python\Python36\;C:\Users\Angel\Videos\flutter\bin;C:\Users\Angel\AppData\Local\Programs\Microsoft VS Code\bin]
这是代码:
import pyrebase
config = {
"apiKey":"AIzaSyDphkVRuW39CyUbLmT5OkeZ2YmAUhwEUm4",
"authDomain":"test-bc3ec",
"databaseURL":"https://test-bc3ec.firebaseio.com/",
"storageBucket":"gs://test-bc3ec.appspot.com/"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
uder = db.child("Nuevo").get()
print(uder.val())
#def stream_handler(message):
# print(message['path'])
# print(message['data'])
#myStream = db.child('Nuevo').stream(stream_handler)
storage = firebase.storage()
myfile = open("Captura.PNG","rb")
bytesm = myfile.read()
fbupload = storage.child("/test/").put(bytesm)
也试试 firebase_admin
import firebase_admin
from firebase_admin import credentials,db,storage
cred = credentials.Certificate("nuevo.json")
firebase_admin.initialize_app(cred,{
'databaseURL':'https://test-bc3ec.firebaseio.com/'
})
s = firebase_admin.storage()
s.child("imagenes/Captura.PNG").put("Captura.PNG")
此代码错误:
Traceback (most recent call last):
File "C:\Users\Angel\Documents\respaldo\firebase_ad.py", line 13, in <module>
s = firebase_admin.storage()
TypeError: 'module' object is not callable
[Finished in 0.8s]
但是也不行
pyrebase 第二
storage = firebase.storage()
myfile = open("Captura.PNG","rb")
bytesm = myfile.read()
fbupload = storage.child("/test/Captura.png").put(bytesm)
Question: Invalid HTTP method/URL pair
config["storageBucket"]
使用您的
config
:"storageBucket":"gs://test-bc3ec.appspot.com/"
Output:
I getInvalid HTTP method/URL pair.
"error": { "code": 400, "message": "Invalid HTTP method/URL pair." }
改为
注意:删除了前导
gs://
和尾随/
。"storageBucket":"test-bc3ec.appspot.com"
Output:
I getPermissin denied
instead ofInvalid HTTP method/URL pair
,
as i can't auth againsttest-bc3ec
"error": { "code": 403, "message": "Permission denied. Could not perform this operation" }
-
put
The put method takes the path to the local file and an optional user token.storage = firebase.storage() # as admin storage.child("images/example.jpg").put("example2.jpg") # as user storage.child("images/example.jpg").put("example2.jpg", user['idToken'])
你的
storage
注:
"test"
不带前导/
。storage = firebase.storage() local_file_path = "Captura.PNG" storage_file_path = "test/Captura.PNG" fbupload = storage.child(storage_file_path).put(local_file_path)
请报告第 3 步,因为我无法验证这一点。
测试 Python:3.4.2 - Pyrebase:3.0.27