Django Project "NoReverseMatch at"

I try to reauthorized user and get token after redirect using response url but this issue occurs

python-facebook-api 0.19.0

#Facebook Api
import hashlib
import hmac
import logging
import re
import time
from urllib.parse import parse_qsl, urlparse
from typing import Dict, List, Optional, Tuple
from warnings import warn

import requests
from requests import Response
from requests_oauthlib.oauth2_session import OAuth2Session
from requests_oauthlib.compliance_fixes.facebook import facebook_compliance_fix

from pyfacebook import RateLimit, PercentSecond, FacebookError, LibraryError

logger = logging.getLogger(__name__)

class GraphAPI:
    GRAPH_URL = ""
    DEFAULT_SCOPE = ["public_profile"]
    STATE = "facebook_access"

    def __init__(
        app_id: Optional[str] = None,
        app_secret: Optional[str] = None,
        access_token: Optional[str] = None,
        application_only_auth: bool = False,
        oauth_flow: bool = False,
        version: Optional[str] = None,
        ignore_version_check: Optional[bool] = False,
        sleep_on_rate_limit: bool = True,
        sleep_seconds_mapping: Optional[Dict[int, int]] = None,
        base_url: Optional[str] = None,
        timeout: Optional[int] = None,
        proxies: Optional[dict] = None,
        instagram_business_id: Optional[str] = None,
        authorization_url: Optional[str] = None,
        access_token_url: Optional[str] = None,
        redirect_uri: Optional[str] = None,
        scope: Optional[List[str]] = None,
        state: Optional[str] = None,
        self.app_id = app_id
        self.app_secret = app_secret
        self.access_token = access_token

        self.session = requests.Session()
        self.__timeout = timeout
        self.proxies = proxies
        self.sleep_on_rate_limit = sleep_on_rate_limit
        self.sleep_seconds_mapping = self._build_sleep_seconds_resource(
        self.rate_limit = RateLimit()
        self.instagram_business_id = instagram_business_id

        # Override url for send request
        self.base_url = base_url if base_url else self.GRAPH_URL
        self.authorization_url = (
            authorization_url if authorization_url else self.AUTHORIZATION_URL
        self.access_token_url = (
            access_token_url if access_token_url else self.EXCHANGE_ACCESS_TOKEN_URL
        self.redirect_uri = redirect_uri if redirect_uri else self.DEFAULT_REDIRECT_URI
        self.scope = scope if scope else self.DEFAULT_SCOPE
        self.state = state if state else self.STATE

        if version is None:
            # default version is last new.
            self.version = self.VALID_API_VERSIONS[-1]
        elif not ignore_version_check:
            if not version.startswith("v"):
                version = "v" + version
            version_regex = re.compile(r"^v\d*.\d{1,2}$")
            match =
            if match is not None:
                self.version = version
                raise LibraryError(
                        "message": f"Invalid version {version}. You can provide with like: 14.0 or v14.0"
            self.version = version

        # Token
        if access_token:
            self.access_token = access_token
        elif application_only_auth and all([self.app_id, self.app_secret]):
            data = self.get_app_token()
            self.access_token = data["access_token"]
        elif oauth_flow and all([self.app_id, self.app_secret]):
            raise LibraryError({"message": "Need access token"})
def get_authorization_url(
        redirect_uri: Optional[str] = None,
        scope: Optional[List[str]] = None,
        state: Optional[str] = None,
    ) -> Tuple[str, str]:
        Build authorization url to do oauth.

        :param redirect_uri: The URL that you want to redirect the person logging in back to.
            Note: Your redirect uri need be set to `Valid OAuth redirect URIs` items in App Dashboard.
        :param scope: A list of permission string to request from the person using your app.
        :param state: A CSRF token that will be passed to the redirect URL.
        :param kwargs: Additional parameters for oauth.
        :return: URL to do oauth and state
        session = self._get_oauth_session(
            redirect_uri=redirect_uri, scope=scope, state=state, **kwargs
        authorization_url, state = session.authorization_url(url=self.authorization_url)
        return authorization_url, state
from django.shortcuts import render, redirect
from pyfacebook import GraphAPI

API = GraphAPI(

def facebook_auth(request):
    auth_url = API.get_authorization_url(
    )  # Assuming API is your GraphAPI instance
    print("facebook_url::", auth_url)
    return redirect(auth_url)

def facebook_access(request):
    response_url = request.build_absolute_uri()
    access_token = API.exchange_user_access_token(response=response_url)
    print("access_token::", access_token)
    return render(request, "dashboard/social_accounts.html")
from django.urls import path
from signin.views import (facebook_auth, facebook_access,)
    urlpatterns = [
    path("facebook_auth", facebook_auth, name="facebook_auth"),
    path("facebook_access", facebook_access, name="facebook_access"),

What Should i do to resolve this issue this an API package fault or mine??
Thank You

Please post, as text (not an image), the complete error log and traceback from your server console where this error is occuring.

[2024-04-02 19:32:33 +0530] [81770] [CRITICAL] WORKER TIMEOUT (pid:81772)
[2024-04-02 14:02:33 +0000] [81772] [INFO] Worker exiting (pid: 81772)
[2024-04-02 19:32:33 +0530] [81770] [ERROR] Worker (pid:81772) exited with code 1
[2024-04-02 19:32:33 +0530] [81770] [ERROR] Worker (pid:81772) exited with code 1.
[2024-04-02 19:32:33 +0530] [82278] [INFO] Booting worker with pid: 82278
facebook_url:: ('', 'facebook_access')
Internal Server Error: /facebook_auth
Traceback (most recent call last):
  File "/home/cord4/Kathan/social_manager/env/lib/python3.8/site-packages/django/core/handlers/", line 55, in inner
    response = get_response(request)
  File "/home/cord4/Kathan/social_manager/env/lib/python3.8/site-packages/django/core/handlers/", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/cord4/Kathan/social_manager/social_manager/signin/", line 295, in facebook_auth
    return redirect(auth_url)
  File "/home/cord4/Kathan/social_manager/env/lib/python3.8/site-packages/django/", line 48, in redirect
    return redirect_class(resolve_url(to, *args, **kwargs))
  File "/home/cord4/Kathan/social_manager/env/lib/python3.8/site-packages/django/", line 145, in resolve_url
    return reverse(to, args=args, kwargs=kwargs)
  File "/home/cord4/Kathan/social_manager/env/lib/python3.8/site-packages/django/urls/", line 88, in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "/home/cord4/Kathan/social_manager/env/lib/python3.8/site-packages/django/urls/", line 828, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for '('', 'facebook_access')' not found. '('', 'facebook_access')' is not a valid view function or pattern name.

This value for facebook_url is a tuple and not a url. You’re not passing an appropriate value to:

See the docs for redirect for what you can pass as the parameter.

Thank You :slightly_smiling_face: it works.