GithubHelp home page GithubHelp logo

Comments (2)

nateprewitt avatar nateprewitt commented on July 2, 2024

Hi @KenKout, can you please supply the full set of information requested in the ticket template and the complete stacktrace?

What's provided currently is not reproducible.

This works as expected:

import requests
r = requests.get('https://httpbin.org/redirect-to?url=app://test', allow_redirects=False)

From the error, it looks like the location is being parsed at some point, it's not clear where that's happening.

from requests.

KenKout avatar KenKout commented on July 2, 2024
import requests
from requests.structures import CaseInsensitiveDict

url = "https://sandbox.moodledemo.net/login/index.php"
s = requests.Session()
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/x-www-form-urlencoded"
headers["Origin"] = "https://sandbox.moodledemo.net"
headers["Referer"] = "https://sandbox.moodledemo.net/login/index.php"
headers["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0"


resp = s.get(url, headers=headers)
logintoken = resp.text.split('logintoken" value="')[1].split('"')[0]
data = f"anchor=&logintoken={logintoken}&username=admin&password=sandbox"
resp = s.post(url, headers=headers, data=data)
print(resp.text)

url = 'https://sandbox.moodledemo.net/admin/tool/mobile/launch.php?service=moodle_mobile_app&passport=1&urlscheme=moodlemobile'
resp = s.get(url, headers=headers)
print(resp.text)

Hi, this is the script, sorry for late response
It works well when I use library httpx

import requests
from requests.structures import CaseInsensitiveDict

url = "https://sandbox.moodledemo.net/login/index.php"
s = requests.Session()
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/x-www-form-urlencoded"
headers["Origin"] = "https://sandbox.moodledemo.net"
headers["Referer"] = "https://sandbox.moodledemo.net/login/index.php"
headers["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0"


resp = s.get(url, headers=headers)
logintoken = resp.text.split('logintoken" value="')[1].split('"')[0]
data = f"anchor=&logintoken={logintoken}&username=admin&password=sandbox"
resp = s.post(url, headers=headers, data=data)
print(resp.text)

import httpx
url = 'https://sandbox.moodledemo.net/admin/tool/mobile/launch.php?service=moodle_mobile_app&passport=1&urlscheme=moodlemobile'
resp = httpx.get(url, headers=headers, cookies=s.cookies)
print(resp.headers)

In case you can't try to recreate the error, it's because moodle sandbox resets every hour
So when you want to try it
Moodle Setting
(username: admin; password: sandbox)
Come to this page and change Type of login into this
image

from requests.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.