0

I was trying to create a django project. Everything was fine until I did a get request using requests.get() in python in my views.py

Following is what my views.py have

from django.http import HttpResponse
from django.shortcuts import render
import re, requests

def codify_data(data_raw):
    data = data_raw.json()['data']
    if language == 'web':
        html_cd = data['sourceCode']
        css_cd = data['cssCode']
        js_cd = data['jsCode']

def home_page(request):
    return render(request,'home/index.html')
    
def code(request):
    link = request.GET.get('link', 'https://code.sololearn.com/c5I5H9T7viyb/?ref=app')
    
    result = re.search(r'https://code.sololearn.com/(.*)/?ref=app',link).group(1)[0:-2]
    data_raw = requests.get('https://api2.sololearn.com/v2/codeplayground/usercodes/'+result)
    codify_data(data_raw)

The error is shown below:

image

Sasha
  • 827
  • 1
  • 9
  • 16
  • Hi, you already tried something like requests.get(request_url, headers=header, timeout=10)? If there is no headers needed you can write requests.get(request_url, timeout=10) – Luiz Dec 11 '21 at 15:27
  • @Luiz I tried it but It didn't worked for me. Let me clarify that the app I am using is pydroid3 – ayush kumar Dec 11 '21 at 15:34
  • You can try to access this route in postman to check if this is a problem of requests library or the url – Luiz Dec 11 '21 at 16:33
  • @Luiz how can I do it in a smartphone? – ayush kumar Dec 12 '21 at 02:51
  • Oh it's true you are using a smartphone, but if the request method is get you can copy this url and post in a browser – Luiz Dec 12 '21 at 15:20

0 Answers0