title: How do you get the params from a URL after running it with Python requests?
body: <p>I know how to do it with a current URL e.g.</p>
  
  <pre><code>&gt;&gt;&gt; payload = {'key1': 'value1', 'key2': ['value2', 'value3']}
  
  &gt;&gt;&gt; r = requests.get('http://httpbin.org/get', params=payload)
  &gt;&gt;&gt; print(r.url)
  </code></pre>
  
  <p>But what about if after you visit a URL, such as one with OAuth, for example</p>
  
  <pre><code>authorize_url = facebook.get_authorize_url(**params)
  requests.get(authorized_url)
  </code></pre>
  
  <p>The URL will then direct to one such as <code>https://localhost:5000/authorized?code=AQCvF</code>. How do I get the <code>code=AQCvF</code>?</p>
  
  <p>I could probably do something like, get the address of the current browser and then parse the URL, but is there a cleaner way?</p>
  
  <hr>
  
  <p>Complete code is below:</p>
  
  <p><strong>index.j2</strong></p>
  
  <pre><code>&lt;p&gt;&lt;a href="/facebook-login"&gt;Login with Facebook&lt;/a&gt;&lt;/p&gt;
  </code></pre>
  
  <p><strong>routes.py</strong></p>
  
  <pre><code>app.add_route('/facebook-login', LoginHandler('index.j2'))
  app.add_route('/authorized', AuthorizedHandler('index.j2'))
  </code></pre>
  
  <p><strong>handlers.py</strong></p>
  
  <pre><code>from rauth.service import OAuth2Service
  import requests
  import os
  
  # rauth OAuth 2.0 service wrapper
  graph_url = 'https://graph.facebook.com/'
  facebook = OAuth2Service(name='facebook',
                           authorize_url='https://www.facebook.com/dialog/oauth',
                           access_token_url=graph_url + 'oauth/access_token',
                           client_id=FB_CLIENT_ID,
                           client_secret=FB_CLIENT_SECRET,
                           base_url=graph_url)
  
  
  class AuthorizedHandler(TemplateHandler):
  
      def on_get(self, req, res):
          code = self.requests.get['code']
          data = dict(code=code, redirect_uri=REDIRECT_URI)
          session = facebook.get_auth_session(data=data)
  
          # response
          me = session.get('me').json()
          print('me', me)
  
          UserController.create(me['username'], me['id'])
  
  
  class LoginHandler(TemplateHandler):
  
      async def on_get(self, req, res):
          # visit URL and client authorizes
          params = {'response_type': 'code',
                    'redirect_uri': REDIRECT_URI}
  
          webbrowser.open(facebook.get_authorize_url(**params))
  
          response = requests.get(facebook.get_authorize_url(**params))
          print(response.url)
  </code></pre>