0

我正在创建 python django web 应用程序以在 firebase 实时数据库上上传数据。我正在使用 python3 和 pyrebase4。firebase 身份验证已完成。用户登录和登录程序完成。我在第三步面临错误,即在实时数据库上上传数据。
显示运行时错误的行是:

db.child('users').child(a).child('reports').child(millis).set(data)

运行时错误是:

HTTPConnectionPool Max retries exceeded with url: /%5B'localId'%5D/reports/1617203893.json 
Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001C44758D8E0>: 
Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

视图.py

from django.shortcuts import render
from django.contrib import auth
import pyrebase


config={

    'apiKey': "AIzaSyDWBmMMaF3YJO7ZxMXgbBRzqw7hqe564vc",
    'databaseURL': 'http://'+'',
    'authDomain': "cpanel-103d6.firebaseapp.com",
    'projectId': "cpanel-103d6",
    'storageBucket': "cpanel-103d6.appspot.com",
    'messagingSenderId': "489072871004",
    'appId': "1:489072871004:web:fd717d9bd6d0a4007f4899",
    "serviceAccount": "C:/Users/Subijoy Acharya/Videos/cpanel-103d6-firebase-adminsdk-l3x1i-7c7fca8614.json"

}


firebase= pyrebase.initialize_app(config)
db= firebase.database()
authe =firebase.auth()

def signin(request):
    return render(request, "signin.html")

def postsign(request):
    email = request.POST.get('email')
    passw = request.POST.get('pass')

    try:
        user = authe.sign_in_with_email_and_password(email, passw)
    except:
        message = 'invalid credentials'
        return render(request, 'signin.html', {'messg': message})

    print(user['idToken'])
    session_id= user['idToken']
    request.session['uid']=str(session_id)
    return render(request, 'welcome.html', {'e': email})

def logout(request):
    auth.logout(request)
    return render(request,'signin.html')

def signup(request):
    return render(request,'signup.html')

def postsignup(request):
    name=request.POST.get('name')
    email=request.POST.get('email')
    password= request.POST.get('passw')
    user=authe.create_user_with_email_and_password(email,password)
    uid = user['localId']
    data={"name":name,"status":'1'}
    db.child("users").set(uid).child('details').set(data)

    return render(request,"signin.html")

def create(request):
    return render(request,"create.html")

def post_create(request):
    import time
    from datetime import datetime,timezone
    import pytz

    tz= pytz.timezone('Asia/Kolkata')
    timenow= datetime.now(timezone.utc).astimezone()
    millis=int(time.mktime(timenow.timetuple()))
    print('mili'+str(millis))
    work=request.POST.get('work')
    progress=request.POST.get('progress')
    idtoken=request.session['uid']
    a=authe.get_account_info(idtoken)
    a=a['users']
    a=a[0]
    a=['localId']
    print('info'+str(a))
    data={
        "work":work,
        "progress":progress
    }

    db.child('users').child(a).child('reports').child(millis).set(data)

    return render(request, 'welcome.html')

创建.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">


</head>
<body>
    <h1>Dear User,Upload Document Here</h1>

  <form action="/post_create/" method="post">
      {% csrf_token %}
      Work Assigned : <input type = "text" name="work" required>
      Progress : <textarea rows="5" cols="40" name="progress" required></textarea>
      <br><br>
      <input type="submit" value="SUBMIT">
      <button type="button" onclick="location.href='{% url 'signup' %}'">Sign Up</button>
  </form>
    <br><br>
  <div><button type="button" onclick="location.href='{% url 'log' %}'"> LOGOUT </button></div>

</body>
</html>

网址.py

from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
    path('admin/', views.signin),
    path('postsign/', views.postsign),
    path('logout/', views.logout, name='log'),
    path('signup/',views.signup,name='signup'),
    path('postsignup/',views.postsignup,name='postsignup'),
    path('create/',views.create,name='create'),
    path('post_create/',views.post_create,name='post_create')
]

链接中给出的 pyrebase 文档: https ://github.com/thisbejim/Pyrebase

这是我引用的视频: https ://www.youtube.com/watch?v=bq0AszeDZf4&list=PLhPDb5zFmGR2VfXiN2y-1V0qdRik7Cc0K&index=4

4

0 回答 0