gurudesh/pytracebugs huggingface dataset:
# Buggy code
def append_to_value(self, value):
    self._value_buffer.seek(0, os.SEEK_END)
    self._value_buffer.write(value)

    self.last_modified = datetime.datetime.utcnow()
    self._etag = None  # must recalculate etag
    if self._is_versioned:
        self._version_id = str(uuid.uuid4())
    else:
        self._version_id = None


# Traceback (botocore.exceptions.ClientError)
Traceback (most recent call last):
File "/Users/myuser/projects/project/web/pdf_file_downloader.py", line 16, in download
self.s3.download_file(self.bucket_name, self.file_name, self.local_path())
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/boto3/s3/inject.py", line 172, in download_file
extra_args=ExtraArgs, callback=Callback)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/boto3/s3/transfer.py", line 307, in download_file
future.result()
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/futures.py", line 106, in result
return self._coordinator.result()
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/futures.py", line 265, in result
raise self._exception
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/tasks.py", line 126, in __call__
return self._execute_main(kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/tasks.py", line 150, in _execute_main
return_value = self._main(**kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/download.py", line 512, in _main
Bucket=bucket, Key=key, **extra_args)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/botocore/client.py", line 626, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (416) when calling the GetObject operation: Requested Range Not Satisfiable

# Fixed code
def append_to_value(self, value):
    self.contentsize += len(value)
    self._value_buffer.seek(0, os.SEEK_END)
    self._value_buffer.write(value)

    self.last_modified = datetime.datetime.utcnow()
    self._etag = None  # must recalculate etag
    if self._is_versioned:
        self._version_id = str(uuid.uuid4())
    else:
        self._version_id = None
# Buggy code
def size(self):
    self._value_buffer.seek(0, os.SEEK_END)
    return self._value_buffer.tell()


# Traceback (botocore.exceptions.ClientError)
Traceback (most recent call last):
File "/Users/myuser/projects/project/web/pdf_file_downloader.py", line 16, in download
self.s3.download_file(self.bucket_name, self.file_name, self.local_path())
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/boto3/s3/inject.py", line 172, in download_file
extra_args=ExtraArgs, callback=Callback)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/boto3/s3/transfer.py", line 307, in download_file
future.result()
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/futures.py", line 106, in result
return self._coordinator.result()
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/futures.py", line 265, in result
raise self._exception
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/tasks.py", line 126, in __call__
return self._execute_main(kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/tasks.py", line 150, in _execute_main
return_value = self._main(**kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/download.py", line 512, in _main
Bucket=bucket, Key=key, **extra_args)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/botocore/client.py", line 626, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (416) when calling the GetObject operation: Requested Range Not Satisfiable

# Fixed code
def size(self):
    return self.contentsize
# Buggy code
def __getstate__(self):
    state = self.__dict__.copy()
    state["value"] = self.value
    del state["_value_buffer"]
    return state


# Traceback (botocore.exceptions.ClientError)
Traceback (most recent call last):
File "/Users/myuser/projects/project/web/pdf_file_downloader.py", line 16, in download
self.s3.download_file(self.bucket_name, self.file_name, self.local_path())
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/boto3/s3/inject.py", line 172, in download_file
extra_args=ExtraArgs, callback=Callback)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/boto3/s3/transfer.py", line 307, in download_file
future.result()
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/futures.py", line 106, in result
return self._coordinator.result()
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/futures.py", line 265, in result
raise self._exception
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/tasks.py", line 126, in __call__
return self._execute_main(kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/tasks.py", line 150, in _execute_main
return_value = self._main(**kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/download.py", line 512, in _main
Bucket=bucket, Key=key, **extra_args)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/botocore/client.py", line 626, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (416) when calling the GetObject operation: Requested Range Not Satisfiable

# Fixed code
def __getstate__(self):
    state = self.__dict__.copy()
    state["value"] = self.value
    del state["_value_buffer"]
    del state["lock"]
    return state
# Buggy code
def __setstate__(self, state):
    self.__dict__.update({k: v for k, v in six.iteritems(state) if k != "value"})

    self._value_buffer = tempfile.SpooledTemporaryFile(max_size=self._max_buffer_size)
    self.value = state["value"]


# Traceback (botocore.exceptions.ClientError)
Traceback (most recent call last):
File "/Users/myuser/projects/project/web/pdf_file_downloader.py", line 16, in download
self.s3.download_file(self.bucket_name, self.file_name, self.local_path())
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/boto3/s3/inject.py", line 172, in download_file
extra_args=ExtraArgs, callback=Callback)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/boto3/s3/transfer.py", line 307, in download_file
future.result()
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/futures.py", line 106, in result
return self._coordinator.result()
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/futures.py", line 265, in result
raise self._exception
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/tasks.py", line 126, in __call__
return self._execute_main(kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/tasks.py", line 150, in _execute_main
return_value = self._main(**kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/s3transfer/download.py", line 512, in _main
Bucket=bucket, Key=key, **extra_args)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/myuser/Library/Caches/pypoetry/virtualenvs/project-X5XCMv3p-py3.6/lib/python3.6/site-packages/botocore/client.py", line 626, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (416) when calling the GetObject operation: Requested Range Not Satisfiable

# Fixed code
def __setstate__(self, state):
    self.__dict__.update({k: v for k, v in six.iteritems(state) if k != "value"})

    self._value_buffer = tempfile.SpooledTemporaryFile(max_size=self._max_buffer_size)
    self.value = state["value"]
    self.lock = threading.Lock()
# Buggy code
def __init__(self, job_id, archive_id):
    self.job_id = job_id
    self.archive_id = archive_id


# Traceback (AttributeError)
127.0.0.1 - - [06/Sep/2017 14:40:32] "POST /kefo/vaults/testvault/archives HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/serving.py", line 209, in run_wsgi
execute(self.server.app)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/serving.py", line 197, in execute
application_iter = app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/server.py", line 92, in __call__
return backend_app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/core/utils.py", line 131, in __call__
result = self.callback(request, request.url, {})
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/glacier/responses.py", line 71, in vault_archive_response
return response_instance._vault_archive_response(request, full_url, headers)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/glacier/responses.py", line 75, in _vault_archive_response
body = request.body
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'body'

# Fixed code
def __init__(self, job_id, tier, arn, archive_id):
    self.job_id = job_id
    self.tier = tier
    self.arn = arn
    self.archive_id = archive_id
    Job.__init__(self, tier)
# Buggy code
def __init__(self, vault_name, region):
    self.vault_name = vault_name
    self.region = region
    self.archives = {}
    self.jobs = {}


# Traceback (AttributeError)
127.0.0.1 - - [06/Sep/2017 14:40:32] "POST /kefo/vaults/testvault/archives HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/serving.py", line 209, in run_wsgi
execute(self.server.app)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/serving.py", line 197, in execute
application_iter = app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/server.py", line 92, in __call__
return backend_app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/core/utils.py", line 131, in __call__
result = self.callback(request, request.url, {})
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/glacier/responses.py", line 71, in vault_archive_response
return response_instance._vault_archive_response(request, full_url, headers)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/glacier/responses.py", line 75, in _vault_archive_response
body = request.body
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'body'

# Fixed code
def __init__(self, vault_name, region):
    self.st = datetime.datetime.now()
    self.vault_name = vault_name
    self.region = region
    self.archives = {}
    self.jobs = {}
# Buggy code
def get_archive_body(self, archive_id):
    return self.archives[archive_id]


# Traceback (AttributeError)
127.0.0.1 - - [06/Sep/2017 14:40:32] "POST /kefo/vaults/testvault/archives HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/serving.py", line 209, in run_wsgi
execute(self.server.app)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/serving.py", line 197, in execute
application_iter = app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/server.py", line 92, in __call__
return backend_app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/core/utils.py", line 131, in __call__
result = self.callback(request, request.url, {})
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/glacier/responses.py", line 71, in vault_archive_response
return response_instance._vault_archive_response(request, full_url, headers)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/glacier/responses.py", line 75, in _vault_archive_response
body = request.body
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'body'

# Fixed code
def get_archive_body(self, archive_id):
    return self.archives[archive_id]["body"]
# Buggy code
def initiate_job(self, archive_id):
    job_id = get_job_id()
    job = ArchiveJob(job_id, archive_id)
    self.jobs[job_id] = job
    return job_id


# Traceback (AttributeError)
127.0.0.1 - - [06/Sep/2017 14:40:32] "POST /kefo/vaults/testvault/archives HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/serving.py", line 209, in run_wsgi
execute(self.server.app)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/serving.py", line 197, in execute
application_iter = app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/server.py", line 92, in __call__
return backend_app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/core/utils.py", line 131, in __call__
result = self.callback(request, request.url, {})
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/glacier/responses.py", line 71, in vault_archive_response
return response_instance._vault_archive_response(request, full_url, headers)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/glacier/responses.py", line 75, in _vault_archive_response
body = request.body
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'body'

# Fixed code
def initiate_job(self, job_type, tier, archive_id):
    job_id = get_job_id()

    if job_type == "inventory-retrieval":
        job = InventoryJob(job_id, tier, self.arn)
    elif job_type == "archive-retrieval":
        job = ArchiveJob(job_id, tier, self.arn, archive_id)

    self.jobs[job_id] = job
    return job_id
# Buggy code
def initiate_job(self, vault_name, archive_id):
    vault = self.get_vault(vault_name)
    job_id = vault.initiate_job(archive_id)
    return job_id


# Traceback (AttributeError)
127.0.0.1 - - [06/Sep/2017 14:40:32] "POST /kefo/vaults/testvault/archives HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/serving.py", line 209, in run_wsgi
execute(self.server.app)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/serving.py", line 197, in execute
application_iter = app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/server.py", line 92, in __call__
return backend_app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/core/utils.py", line 131, in __call__
result = self.callback(request, request.url, {})
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/glacier/responses.py", line 71, in vault_archive_response
return response_instance._vault_archive_response(request, full_url, headers)
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/moto/glacier/responses.py", line 75, in _vault_archive_response
body = request.body
File "/Users/kford1/Work/motoenv/lib/python3.5/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'body'

# Fixed code
def initiate_job(self, vault_name, job_type, tier, archive_id):
    vault = self.get_vault(vault_name)
    job_id = vault.initiate_job(job_type, tier, archive_id)
    return job_id
# Buggy code
def get_s3_bucket_list(boto3_session):
    client = boto3_session.client("s3")
    # NOTE no paginator available for this operation
    return client.list_buckets()


# Traceback (botocore.exceptions.ClientError)
ERROR:cartography.sync:Unhandled exception during sync stage 'aws'
Traceback (most recent call last):
File "/usr/local/bin/cartography", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/site-packages/cartography/cli.py", line 216, in main
return CLI(default_sync, prog='cartography').main(argv)
File "/usr/local/lib/python3.6/site-packages/cartography/cli.py", line 196, in main
return cartography.sync.run_with_config(self.sync, config)
File "/usr/local/lib/python3.6/site-packages/cartography/sync.py", line 135, in run_with_config
return sync.run(neo4j_driver, config)
File "/usr/local/lib/python3.6/site-packages/cartography/sync.py", line 69, in run
stage_func(neo4j_session, config)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 106, in start_aws_ingestion
_sync_multiple_accounts(neo4j_session, aws_accounts, regions, config.update_tag, common_job_parameters)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 44, in _sync_multiple_accounts
_sync_one_account(neo4j_session, boto3_session, account_id, regions, sync_tag, common_job_parameters)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/__init__.py", line 22, in _sync_one_account
s3.sync(neo4j_session, boto3_session, account_id, sync_tag, common_job_parameters)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/s3.py", line 326, in sync
load_s3_details(neo4j_session, acl_and_policy_data_iter, current_aws_account_id, aws_update_tag)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/s3.py", line 136, in load_s3_details
for bucket, acl, policy in s3_details_iter:
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/s3.py", line 26, in get_s3_bucket_details
acl = get_acl(bucket, client)
File "/usr/local/lib/python3.6/site-packages/cartography/intel/aws/s3.py", line 54, in get_acl
acl = client.get_bucket_acl(Bucket=bucket['Name'])
File "/Users/drosenbloom/Library/Python/3.6/lib/python/site-packages/botocore/client.py", line 272, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/drosenbloom/Library/Python/3.6/lib/python/site-packages/botocore/client.py", line 576, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (IllegalLocationConstraintException) when calling the GetBucketAcl operation: The me-south-1 location constraint is incompatible for the region specific endpoint this request was sent to.

# Fixed code
def get_s3_bucket_list(boto3_session):
    client = boto3_session.client("s3")
    # NOTE no paginator available for this operation
    buckets = client.list_buckets()
    for bucket in buckets["Buckets"]:
        bucket["Region"] = client.get_bucket_location(Bucket=bucket["Name"])[
            "LocationConstraint"
        ]
    return buckets
# Buggy code
def sync_gcp_subnets(
    neo4j_session, compute, project_id, regions, gcp_update_tag, common_job_parameters
):
    for r in regions:
        subnet_res = get_gcp_subnets(project_id, r, compute)
        subnets = transform_gcp_subnets(subnet_res)
        load_gcp_subnets(neo4j_session, subnets, gcp_update_tag)
        cleanup_gcp_subnets(neo4j_session, common_job_parameters)


# Traceback (googleapiclient.errors.HttpError)
Traceback (most recent call last):
File "{path}/site-packages/cartography/sync.py", line 71, in run
stage_func(neo4j_session, config)
File "{path}/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "{path}/site-packages/cartography/intel/gcp/__init__.py", line 218, in start_gcp_ingestion
_sync_multiple_projects(neo4j_session, resources, projects, config.update_tag, common_job_parameters)
File "{path}/site-packages/cartography/intel/gcp/__init__.py", line 177, in _sync_multiple_projects
_sync_single_project(neo4j_session, resources, project_id, gcp_update_tag, common_job_parameters)
File "{path}/site-packages/cartography/intel/gcp/__init__.py", line 155, in _sync_single_project
gke.sync_gke_clusters(neo4j_session, resources.container, project_id, gcp_update_tag, common_job_parameters)
File "{path}/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "{path}/site-packages/cartography/intel/gcp/gke.py", line 197, in sync_gke_clusters
gke_res = get_gke_clusters(container, project_id)
File "{path}/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "{path}/site-packages/cartography/intel/gcp/gke.py", line 28, in get_gke_clusters
res = req.execute()
File "{path}/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "{path}/site-packages/googleapiclient/http.py", line 907, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://container.googleapis.com/v1/projects/{ProjectName}}/zones/-/clusters?alt=json returned "Required "container.clusters.list" permission(s) for "projects/{ProjectName}".">

# Fixed code
def sync_gcp_subnets(
    neo4j_session, compute, project_id, regions, gcp_update_tag, common_job_parameters
):
    for r in regions:
        subnet_res = get_gcp_subnets(project_id, r, compute)
        subnets = transform_gcp_subnets(subnet_res)
        load_gcp_subnets(neo4j_session, subnets, gcp_update_tag)
        # TODO scope the cleanup to the current project - https://github.com/lyft/cartography/issues/381
        cleanup_gcp_subnets(neo4j_session, common_job_parameters)
# Buggy code
def get_transit_gateways(boto3_session, region):
    client = boto3_session.client(
        "ec2", region_name=region, config=get_botocore_config()
    )
    return client.describe_transit_gateways()["TransitGateways"]


# Traceback (botocore.exceptions.ClientError)
Traceback (most recent call last):
[...]
File "{PATH}/site-packages/cartography/intel/aws/__init__.py", line 96, in _sync_multiple_accounts
_sync_one_account(neo4j_session, boto3_session, account_id, sync_tag, common_job_parameters)
File "{PATH}/site-packages/cartography/intel/aws/__init__.py", line 44, in _sync_one_account
ec2.sync(neo4j_session, boto3_session, regions, account_id, sync_tag, common_job_parameters)
File "{PATH}/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "{PATH}/site-packages/cartography/intel/aws/ec2/__init__.py", line 35, in sync
sync_transit_gateways(neo4j_session, boto3_session, regions, account_id, sync_tag, common_job_parameters)
File "{PATH}/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "{PATH}/site-packages/cartography/intel/aws/ec2/tgw.py", line 210, in sync_transit_gateways
tgws = get_transit_gateways(boto3_session, region)
File "{PATH}/site-packages/cartography/util.py", line 58, in timed
result = method(*args, **kwargs)
File "{PATH}/site-packages/cartography/util.py", line 78, in inner_function
return func(*args, **kwargs)
File "{PATH}/site-packages/cartography/intel/aws/ec2/tgw.py", line 16, in get_transit_gateways
return client.describe_transit_gateways()["TransitGateways"]
File "{PATH}/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "{PATH}/site-packages/botocore/client.py", line 661, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidAction) when calling the DescribeTransitGateways operation: The action DescribeTransitGateways is not valid for this web service.

# Fixed code
def get_transit_gateways(boto3_session, region):
    client = boto3_session.client(
        "ec2", region_name=region, config=get_botocore_config()
    )
    data = []
    try:
        data = client.describe_transit_gateways()["TransitGateways"]
    except botocore.exceptions.ClientError as e:
        # https://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.html#parsing-error-responses-and-catching-exceptions-from-aws-services
        logger.warning(
            "Could not retrieve Transit Gateways due to boto3 error %s: %s. Skipping.",
            e.response["Error"]["Code"],
            e.response["Error"]["Message"],
        )
    return data
# Buggy code
def add_functionary_key(self, key):
    """
    <Purpose>
      Add the passed functionary public key to the layout's dictionary of keys.

    <Arguments>
      key:
              A functionary public key conformant with
              in_toto.formats.ANY_PUBKEY_SCHEMA.

    <Exceptions>
      securesystemslib.exceptions.FormatError
              If the passed key does not match
              in_toto.formats.ANY_PUBKEY_SCHEMA.

    <Returns>
      The added functionary public key.

    """
    in_toto.formats.ANY_PUBKEY_SCHEMA.check_match(key)
    keyid = key["keyid"]
    self.keys[keyid] = key
    return key


# Traceback (AssertionError)
======================================================================
FAIL: test_in_toto_run_with_byproduct (tests.test_runlib.TestInTotoRun)
Successfully run, verify recorded byproduct.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/lukpueh/in-toto/tests/test_runlib.py", line 495, in test_in_toto_run_with_byproduct
"Python" in link.signed.byproducts.get("stderr"))
AssertionError: False is not true
Stderr:
in_toto.runlib:501:INFO:Running 'test_step'...
in_toto.runlib:524:INFO:Running command 'python --version'...
in_toto.runlib:538:INFO:Creating link metadata...

# Fixed code
def add_functionary_key(self, key):
    """
    <Purpose>
      Add the passed functionary public key to the layout's dictionary of keys.

    <Arguments>
      key:
              A functionary public key conformant with
              securesystemslib.formats.ANY_PUBKEY_SCHEMA.

    <Exceptions>
      securesystemslib.exceptions.FormatError
              If the passed key does not match
              securesystemslib.formats.ANY_PUBKEY_SCHEMA.

    <Returns>
      The added functionary public key.

    """
    securesystemslib.formats.ANY_PUBKEY_SCHEMA.check_match(key)
    keyid = key["keyid"]
    self.keys[keyid] = key
    return key
# Buggy code
def _validate_keys(self):
    """Private method to ensure that the keys contained are right."""
    in_toto.formats.ANY_PUBKEY_DICT_SCHEMA.check_match(self.keys)


# Traceback (AssertionError)
======================================================================
FAIL: test_in_toto_run_with_byproduct (tests.test_runlib.TestInTotoRun)
Successfully run, verify recorded byproduct.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/lukpueh/in-toto/tests/test_runlib.py", line 495, in test_in_toto_run_with_byproduct
"Python" in link.signed.byproducts.get("stderr"))
AssertionError: False is not true
Stderr:
in_toto.runlib:501:INFO:Running 'test_step'...
in_toto.runlib:524:INFO:Running command 'python --version'...
in_toto.runlib:538:INFO:Creating link metadata...

# Fixed code
def _validate_keys(self):
    """Private method to ensure that the keys contained are right."""
    securesystemslib.formats.ANY_PUBKEY_DICT_SCHEMA.check_match(self.keys)
# Buggy code
def sign_gpg(self, gpg_keyid=None, gpg_home=None):
    """
    <Purpose>
      Signs the utf-8 encoded canonical JSON bytes of the Link or Layout object
      contained in `self.signed` using `gpg.functions.gpg_sign_object` and
      appends the created signature to `self.signatures`.

    <Arguments>
      gpg_keyid: (optional)
              A gpg keyid, if omitted the default signing key is used

      gpg_home: (optional)
              The path to the gpg keyring, if omitted the default gpg keyring
              is used

    <Exceptions>
      in_toto.gpg.exceptions.CommandError:
              If the gpg signing command returned a non-zero exit code, e.g.
              because the key has expired.


    <Returns>
      The dictionary representation of the newly created signature.

    """
    signature = in_toto.gpg.functions.gpg_sign_object(
        self.signed.signable_bytes, gpg_keyid, gpg_home
    )

    self.signatures.append(signature)

    return signature


# Traceback (AssertionError)
======================================================================
FAIL: test_in_toto_run_with_byproduct (tests.test_runlib.TestInTotoRun)
Successfully run, verify recorded byproduct.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/lukpueh/in-toto/tests/test_runlib.py", line 495, in test_in_toto_run_with_byproduct
"Python" in link.signed.byproducts.get("stderr"))
AssertionError: False is not true
Stderr:
in_toto.runlib:501:INFO:Running 'test_step'...
in_toto.runlib:524:INFO:Running command 'python --version'...
in_toto.runlib:538:INFO:Creating link metadata...

# Fixed code
def sign_gpg(self, gpg_keyid=None, gpg_home=None):
    """
    <Purpose>
      Signs the utf-8 encoded canonical JSON bytes of the Link or Layout object
      contained in `self.signed` using `gpg.functions.create_signature` and
      appends the created signature to `self.signatures`.

    <Arguments>
      gpg_keyid: (optional)
              A gpg keyid, if omitted the default signing key is used

      gpg_home: (optional)
              The path to the gpg keyring, if omitted the default gpg keyring
              is used

    <Exceptions>
      securesystemslib.gpg.exceptions.CommandError:
              If the gpg signing command returned a non-zero exit code, e.g.
              because the key has expired.


    <Returns>
      The dictionary representation of the newly created signature.

    """
    signature = securesystemslib.gpg.functions.create_signature(
        self.signed.signable_bytes, gpg_keyid, gpg_home
    )

    self.signatures.append(signature)

    return signature
# Buggy code
def _validate_signatures(self):
    """Private method to check that the 'signatures' attribute is a list of
    signatures in the format 'in_toto.formats.ANY_SIGNATURE_SCHEMA'."""

    if not isinstance(self.signatures, list):
        raise securesystemslib.exceptions.FormatError(
            "The Metablock's 'signatures' property has to be of type 'list'."
        )

    for signature in self.signatures:
        in_toto.formats.ANY_SIGNATURE_SCHEMA.check_match(signature)


# Traceback (AssertionError)
======================================================================
FAIL: test_in_toto_run_with_byproduct (tests.test_runlib.TestInTotoRun)
Successfully run, verify recorded byproduct.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/lukpueh/in-toto/tests/test_runlib.py", line 495, in test_in_toto_run_with_byproduct
"Python" in link.signed.byproducts.get("stderr"))
AssertionError: False is not true
Stderr:
in_toto.runlib:501:INFO:Running 'test_step'...
in_toto.runlib:524:INFO:Running command 'python --version'...
in_toto.runlib:538:INFO:Creating link metadata...

# Fixed code
def _validate_signatures(self):
    """Private method to check that the 'signatures' attribute is a list of
    signatures in the format 'securesystemslib.formats.ANY_SIGNATURE_SCHEMA'.
    """

    if not isinstance(self.signatures, list):
        raise securesystemslib.exceptions.FormatError(
            "The Metablock's 'signatures' property has to be of type 'list'."
        )

    for signature in self.signatures:
        securesystemslib.formats.ANY_SIGNATURE_SCHEMA.check_match(signature)
# Buggy code
def import_gpg_public_keys_from_keyring_as_dict(keyids, gpg_home=False):
    """Creates a dictionary of gpg public keys retrieving gpg public keys
    identified by the list of passed `keyids` from the gpg keyring at `gpg_home`.
    If `gpg_home` is False the default keyring is used."""
    key_dict = {}
    for gpg_keyid in keyids:
        pub_key = in_toto.gpg.functions.gpg_export_pubkey(gpg_keyid, homedir=gpg_home)
        in_toto.gpg.formats.PUBKEY_SCHEMA.check_match(pub_key)
        keyid = pub_key["keyid"]
        key_dict[keyid] = pub_key
    return key_dict


# Traceback (AssertionError)
======================================================================
FAIL: test_in_toto_run_with_byproduct (tests.test_runlib.TestInTotoRun)
Successfully run, verify recorded byproduct.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/lukpueh/in-toto/tests/test_runlib.py", line 495, in test_in_toto_run_with_byproduct
"Python" in link.signed.byproducts.get("stderr"))
AssertionError: False is not true
Stderr:
in_toto.runlib:501:INFO:Running 'test_step'...
in_toto.runlib:524:INFO:Running command 'python --version'...
in_toto.runlib:538:INFO:Creating link metadata...

# Fixed code
def import_gpg_public_keys_from_keyring_as_dict(keyids, gpg_home=False):
    """Creates a dictionary of gpg public keys retrieving gpg public keys
    identified by the list of passed `keyids` from the gpg keyring at `gpg_home`.
    If `gpg_home` is False the default keyring is used."""
    key_dict = {}
    for gpg_keyid in keyids:
        pub_key = securesystemslib.gpg.functions.export_pubkey(
            gpg_keyid, homedir=gpg_home
        )
        securesystemslib.formats.GPG_PUBKEY_SCHEMA.check_match(pub_key)
        keyid = pub_key["keyid"]
        key_dict[keyid] = pub_key
    return key_dict
# Buggy code
def request(self, method, url, **kwargs):
    kwargs.setdefault(
        "params",
        {
            "access_token": self.token,
        },
    )
    r = requests.request(method=method, url=url, **kwargs)
    r.raise_for_status()
    json = r.json()
    if check_error(json):
        return json


# Traceback (UnicodeEncodeError)
In [1]: import six

In [2]: def to_text(value, encoding="utf-8"):
...:         if isinstance(value, (six.string_types, six.binary_type)):
...:                 return value.decode(encoding)
...:         if isinstance(value, int):
...:                 return six.text_type(value)
...:         assert isinstance(value, six.text_type)
...:         return value
...:

In [3]: print to_text(u'\u4e2d\u5348')
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-3-9478a71004a0> in <module>()
----> 1 print to_text(u'\u4e2d\u5348')

<ipython-input-2-3b3748f845b1> in to_text(value, encoding)
1 def to_text(value, encoding="utf-8"):
2         if isinstance(value, (six.string_types, six.binary_type)):
----> 3                 return value.decode(encoding)
4         if isinstance(value, int):
5                 return six.text_type(value)

/root/.virtualenvs/wxPortal/lib/python2.7/encodings/utf_8.pyc in decode(input, errors)
14
15 def decode(input, errors='strict'):
---> 16     return codecs.utf_8_decode(input, errors, True)
17
18 class IncrementalEncoder(codecs.IncrementalEncoder):

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

# Fixed code
def request(self, method, url, **kwargs):
    if "params" not in kwargs:
        kwargs["params"] = {"access_token": self.token}
    r = requests.request(method=method, url=url, **kwargs)
    r.raise_for_status()
    json = r.json()
    if check_error(json):
        return json
# Buggy code
def grant_token(self):
    """
    获取 Access Token 。
    详情请参考 http://mp.weixin.qq.com/wiki/index.php?title=通用接口文档

    :param appid: 第三方用户唯一凭证
    :param appsecret: 第三方用户唯一凭证密钥，即 App Secret

    :return: 返回的 JSON 数据包
    """
    return self.get(
        url="https://api.weixin.qq.com/cgi-bin/token",
        params={
            "grant_type": "client_credential",
            "appid": self.appid,
            "secret": self.appsecret,
        },
    )


# Traceback (UnicodeEncodeError)
In [1]: import six

In [2]: def to_text(value, encoding="utf-8"):
...:         if isinstance(value, (six.string_types, six.binary_type)):
...:                 return value.decode(encoding)
...:         if isinstance(value, int):
...:                 return six.text_type(value)
...:         assert isinstance(value, six.text_type)
...:         return value
...:

In [3]: print to_text(u'\u4e2d\u5348')
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-3-9478a71004a0> in <module>()
----> 1 print to_text(u'\u4e2d\u5348')

<ipython-input-2-3b3748f845b1> in to_text(value, encoding)
1 def to_text(value, encoding="utf-8"):
2         if isinstance(value, (six.string_types, six.binary_type)):
----> 3                 return value.decode(encoding)
4         if isinstance(value, int):
5                 return six.text_type(value)

/root/.virtualenvs/wxPortal/lib/python2.7/encodings/utf_8.pyc in decode(input, errors)
14
15 def decode(input, errors='strict'):
---> 16     return codecs.utf_8_decode(input, errors, True)
17
18 class IncrementalEncoder(codecs.IncrementalEncoder):

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

# Fixed code
def grant_token(self):
    """
    获取 Access Token 。
    详情请参考 http://mp.weixin.qq.com/wiki/index.php?title=通用接口文档

    :return: 返回的 JSON 数据包
    """
    return self.get(
        url="https://api.weixin.qq.com/cgi-bin/token",
        params={
            "grant_type": "client_credential",
            "appid": self.appid,
            "secret": self.appsecret,
        },
    )