I am making an API using Django. Since I am giving static type input and getting output in json format. how to give userinput dynamically.
views.py
from django.shortcuts import render,redirect
from django.views.generic import TemplateView
from .models import *
from django.http import HttpResponse
from django.views.generic.edit import FormView
from .forms import TweetForm
from django.views import View
import json
import pdb
import tweepy
from pprint import pprint
import pickle
consumer_key = 'VR95CmIMrv7q7vfDoPcjC8NZS'
consumer_secret = 'YlWo6BzDnhXozSZnvnN1cIcjvRKrJFJVnYA9vvqMDocOdjyBNu'
access_key = '1006840281361047553-JQPFugH9xVNifKRY1b4BjgpdTLiVND'
access_secret = '5R3DXQmf6Xf3FwZHZzqSU3P3oYQAReUqwux9ttj5Gj7K5'
def get_tweets(request):
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
number_of_tweets=10
tweets = api.user_timeline("realdonaldtrump")
tmp= []
for tweet in tweets:
tmp.append({"text":tweet.text,"user":tweet.user.name,"retweet_count":tweet.retweet_count,"img":tweet.user.profile_image_url})
return HttpResponse(json.dumps(tmp))
urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'Tweet/$', views.get_tweets, name='Tweet'),
]
that output is right but we can see tweets = api.user_timeline("realdonaldtrump") line in views.py static input.how to give it dynamically
def get_tweets(request, user):
...
tweets = api.user_timeline(user)
...
return HttpResponse(json.dumps(tmp))
With adding user to view function, you need to change the url a bit
urlpatterns = [
url(r'Tweet/(?P<user>[a-zA-Z0-9_\-]+)/$', views.get_tweets, name='Tweet'),
]
Or you can use the get key and values from the link with request.GET.get('user') and pass that in without needing to /Tweet/realdonaldtrump/ but in that case it would be /Tweet/?user=realdonaldtrump so it is your choice to choose whichever you want.
Related
I am trying to write a test which goes through the signup/login workflow, and then attempts to change the status of a user, which requires them to be logged in. I verified that the first 2 POST requests work (the user is indeed created and then gets a valid auth token after logging in), however I cannot seem to pass in said token in the headers for the 3rd and final POST request. I also checked that the auth_headers variable is indeed set with the correct token, but I keep getting back a 401 status code.
Thanks in advance!
tests.py
from email.headerregistry import ContentTypeHeader
from urllib import request
from wsgiref import headers
from django.http import HttpRequest
from django.test import TestCase, Client
from rest_framework import status
from rest_framework.test import APITestCase
from django.urls import reverse
from rest_framework.authtoken.models import Token
from django.contrib.auth.models import User
from profiles_api.serializers import UserProfileSerializer
from django.contrib.auth import get_user_model
from profiles_api.views import UserLoginApiView
client = Client()
User = get_user_model()
class MyTestCase(APITestCase,UserLoginApiView):
def test_add_status_to_profile(self):
response = self.client.post("/api/profile/", data={
'email':"John#gmail.com",
'name':'Pavle',
'password':'password'
})
response = self.client.post("/api/login/", data={
'username':"John#gmail.com",
'password':'password'
})
auth_headers = {
'Authorization': 'Bearer ' + response.json()['token']
}
response = self.client.post("/api/feed/", content_type='application/json', data={
'status_text':'Hello world!'
}, **auth_headers)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
I have a Django rest API, in which there is an API to get an image from formdata.
from django.shortcuts import render
from django.http.response import JsonResponse
from rest_framework.parsers import JSONParser
from rest_framework import status
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from django.conf import settings
import os
import io
from rest_framework.decorators import api_view
import firebase_admin
from firebase_admin import credentials, firestore, storage
cred = credentials.Certificate("JSON FILE PATH")
firebase_admin.initialize_app(cred,{'storageBucket': 'BUCKET URL'})
#api_view(['GET','POST'])
def login(request):
if request.method == 'POST':
data = request.data
if(type(data)!=dict):
data=data.dict()
file_obj=data['image']
fileName=file_obj.name
blob=bucket.blob(fileName)
blob.upload_from_file(file_obj.file)
blob.make_public()
print("File url", blob.public_url)
return JsonResponse({'username':'Testing post response'})
elif request.method == 'GET':
return JsonResponse({'username':'Testing get response'})
Now, when I send an image in formdata, it is uploading in firebase but not in image format, instead, it is uploading as application/octet-stream type and image is not being displayed. can anyone please help me with this?
change this line
blob.upload_from_file(file_obj.file)
**to**
blob.upload_from_file(file_obj, content_type = file_obj.content_type)
I am writing a view to create a user in project that has logged into another site. Whenever the user logins to that site he/she gets redirected to url:https://localhost:127.0.0.1:8000/auth/ad/reply/.
The site sends me an SAMLResponse from which I want to extract the email address, firstname & lastname for the user.
Following is my views.py and urls.py:
views.py
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
# Create your views here.
#csrf_exempt
def ad_auth(request):
response = request.POST.get('SAMLResponse')
return HttpResponse(response)
urls.py
from django.urls import path
from .views import *
urlpatterns = [
path('auth/ad/reply/', ad_auth, name='ad_auth'),
]
Output:
PHNhbWxwOlJlc3BvbnNlIElEPSJfOTJmYjAyYTMtN2ZiMC00NjZlLTk0NGItNTQxMjhlOGI5NGM2IiBWZXJzaW9uPSIyLjAiIElzc3VlSW5zdGFudD0iMjAyMC0xMS0xMVQxNDowMDoxMi43NzlaIiBEZXN0aW5hdGlvbj0iaHR0cHM6Ly9sb2NhbGhvc3Q6ODAwMC9hdXRoL2FkL3JlcGx5LyIgeG1sbnM6c2FtbHA9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpwcm90b2NvbCI+PElzc3VlciB4bWxucz0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmFzc2VydGlvbiI+aHR0cHM6Ly9zdHMud2luZG93cy5uZXQvYmYzODg4M2EtOGRlNi00NGFhLWJkYzktODFjMzAzY2YxMDMzLzwvSXNzdWVyPjxzYW1scDpTdGF0dXM+PHNhbWxwOlN0YXR1c0NvZGUgVmFsdWU9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpzdGF0dXM6U3VjY2VzcyIvPjwvc2FtbHA6U3RhdHVzPjxBc3NlcnRpb24gSUQ9Il8wYjExNzMwNi03YTI2LTQ2OGQtYTI5Yy1mYTZkMjk2MTQ3MDAiIElzc3VlSW5zdGFudD0iMjAyMC0xMS0xMVQxNDowMDoxMi43NjlaIiBWZXJzaW9uPSIyLjAiIHhtbG5zPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6YXNzZXJ0aW9uIj48SXNzdWVyPmh0dHBzOi8vc3RzLndpb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ZSI+PEF0dHJpYnV0ZVZhbHVlPmxpbmdheWF0YWpheTI4MTBfZ21haWwuY29tI0VYVCNAa3Jpc3AxNTA2Z21haWwub25taWNyb3NvZnQuY29tPC9BdHRyaWJ1dGVWYWx1ZT48L0F0dHJpYnV0ZT48L0F0dHJpYnV0ZVN0YXRlbWVudD48QXV0aG5TdGF0ZW1lbnQgQXV0aG5JbnN0YW50PSIyMDIwLTExLTExVDA3OjI4OjM1LjAwMFoiIFNlc3Npb25JbmRleD0iXzBiMTE3MzA2LTdhMjYtNDY4ZC1hMjljLWZhNmQyOTYxNDcwMCI+PEF1dGhuQ29udGV4dD48QXV0aG5Db250ZXh0Q2xhc3NSZWY+dXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmFjOmNsYXNzZXM6UGFzc3dvcmQ8L0F1dGhuQ29udGV4dENsYXNzUmVmPjwvQXV0aG5Db250ZXh0PjwvQXV0aG5TdGF0ZW1lbnQ+PC9Bc3NlcnRpb24+PC9zYW1scDpSZXNwb25zZT4=
How do I extract information from the following SAMLResponse?
Thanks in Advance.
That is sending you a base64 encoded string.
Decode it and you will find it to be xml.
The email attribute will look something like this
<AttributeValue>xxxxxxxxx2810#gmail.com</AttributeValue>
Some sudo code to get you started
import base64
foo = base64.b64decode("PHNhbWxwOlJlc3BvbnN....") # put your entire string here
print(foo)
You can also use pysaml2 and djangosaml modules to decrypt the SAMLResponse.
I have made an DjangoRestApi and giving user input using postman(POST method).but the error is
TypeError: Object of type 'JSONDecodeError' is not JSON serializable
it is showing in django server where i am going wrong please help Thanks
views.py
import spacy
from django.shortcuts import render,HttpResponse
from django.http import Http404
from rest_framework.views import APIView
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from django.http import JsonResponse
from django.core import serializers
from django.conf import settings
import json
nlp = spacy.load('en_core_web_sm')
#api_view(["POST"])
def nounphrases(requestdata):
try:
text = json.loads(requestdata.body)
nounphrases = []
for word in (nlp((text))):
c = (word.lemma_)
nounphrases.append(c)
output = [{"nounphrases" : nounphrases }]
return JsonResponse(json.dumps(output))
except ValueError as e:
return Response(e,status.HTTP_400_BAD_REQUEST)
I am trying to copy a folder using the google api, python and Django and have managed to get things working with an adaptation of the code found here
But when I try to copy a folder I get:
< HttpError 400 when requesting https://www.googleapis.com/drive/v3/files/FileId/copy?alt=json returned "Bad Request">
import os
import logging
import httplib2
from pprint import pprint
from googleapiclient.discovery import build
from django.contrib.auth.decorators import login_required
from django.conf import settings
from django.http import HttpResponseBadRequest
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from django.http import JsonResponse
from django.db.utils import IntegrityError
from .models import Entries, CredentialsModel
from oauth2client.contrib import xsrfutil
from oauth2client.client import flow_from_clientsecrets
from oauth2client.contrib.django_util.storage import DjangoORMStorage
from .pipeline_lib import pipeline_lib as pipeline
FLOW = flow_from_clientsecrets(
settings.GOOGLE_OAUTH2_CLIENT_SECRETS_JSON,
scope=['https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive.appdata',
'https://www.googleapis.com/auth/drive.metadata'],
redirect_uri='http://somedomain.com:8000/workflow/oauth2callback')
#login_required
def index(request):
storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
credential = storage.get()
if credential is None or credential.invalid == True:
FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY,
request.user)
authorize_url = FLOW.step1_get_authorize_url()
return HttpResponseRedirect(authorize_url)
else:
http = httplib2.Http()
http = credential.authorize(http)
service = build("drive", "v3", http=http)
newfile = {'title': 'New Master 123', 'parents': [{'id': 'folderId'}]}
result = service.files().copy(fileId='folderId',body=newfile).execute()
pprint(result)
# results = service.files().list(pageSize=10,fields="nextPageToken, files(id, name)").execute()
# items = results.get('files', [])
# if not items:
# print('No files found.')
# else:
# print('Files:')
# for item in items:
# print('{0} ({1})'.format(item['name'], item['id']))
return HttpResponse("Hello, world. You're at the index.")
#login_required
def auth_return(request):
credential = FLOW.step2_exchange(request.GET)
storage = DjangoORMStorage(CredentialsModel, 'id', request.user, 'credential')
storage.put(credential)
return HttpResponseRedirect("/workflow")
The problem was that I was attempting to copy a folder and apparently files().copy doesn't operate on a folder at least not one with children but I haven't tested the caveat yet.
After replacing the id of the folder I wanted to copy with the file id of a pdf in the same parent the function ran with out error.
Edit - Now that I've figured this out for myself I stumbled upon a stack overflow post that explains why this is.
In Google Drive SDK how do you copy a folder?