<commit_before>from requests.auth import HTTPBasicAuth
from requests_oauthlib import OAuth1Session, OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient
from oauthlib.common import to_unicode
from . import __version__

import requests
import json

TWITTER_API_VERSION = '1.1'
TWITTER_BASE_API_URL = 'https://%s.twitter.com'


class BirdyException(Exception):
    def __init__(self, msg, resource_url=None, request_method=None, status_code=None, error_code=None, headers=None):
        self._msg = msg
        self.request_method = request_method
        self.resource_url = resource_url
        self.status_code= status_code
        self.error_code = None
        self.headers = None
        
    def __str__(self):
        if self.request_method and self.resource_url:
            return '%s (%s %s)' % (self._msg, self.request_method, self.resource_url)
        return self._msg
        

class TwitterClientError(BirdyException):
    pass
    

class TwitterApiError(BirdyException):
    def __init__(self, msg, response=None, request_method=None, error_code=None):
        kwargs = {'request_method': request_method}
        
        if response is not None:
            kwargs.update({'status_code': response.status_code,<commit_msg>Error code and response headers are never set<commit_after>from requests.auth import HTTPBasicAuth
from requests_oauthlib import OAuth1Session, OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient
from oauthlib.common import to_unicode
from . import __version__

import requests
import json

TWITTER_API_VERSION = '1.1'
TWITTER_BASE_API_URL = 'https://%s.twitter.com'


class BirdyException(Exception):
    def __init__(self, msg, resource_url=None, request_method=None, status_code=None, error_code=None, headers=None):
        self._msg = msg
        self.request_method = request_method
        self.resource_url = resource_url
        self.status_code= status_code
        self.error_code = error_code
        self.headers = headers
        
    def __str__(self):
        if self.request_method and self.resource_url:
            return '%s (%s %s)' % (self._msg, self.request_method, self.resource_url)
        return self._msg
        

class TwitterClientError(BirdyException):
    pass
    

class TwitterApiError(BirdyException):
    def __init__(self, msg, response=None, request_method=None, error_code=None):
        kwargs = {'request_method': request_method}
        
        if response is not None:
            kwargs.update({'status_code': response.status_code,
{'fraction_non_alphanumeric': 0.08094302554027505, 'fraction_numerical': 0.003929273084479371, 'mean_word_length': 3.5464285714285713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2921112', 'n_tokens_mistral': 752, 'n_tokens_neox': 743, 'n_words': 178}