def referer_str(request):
    """ Return Referer HTTP header suitable for logging. """
    referrer = request.headers.get('Referer')
    if referrer is None:
        return referrer
    return to_native_str(referrer, errors='replace')
 Return Referer HTTP header suitable for logging. 
stackoverflow/venv/lib/python3.6/site-packages/scrapy/utils/request.py