即使我通过var传递了它要求的值,我仍然收到此错误。我不确定为什么会这样。
class process_raw_snowplow_event_data(luigi.Task):
dataset_date = luigi.DateParameter(default=date.today() - timedelta(days=1))
# force_run = luigi.BoolParameter()
_start = luigi.DateSecondParameter(default=datetime.utcnow())
file_root = luigi.Parameter()
@staticmethod
def download_s3_file(self, s3_filename):
local_filename = "/Users/xxx/etl/%s" % s3_filename
s3_file_full_path = re.compile(r"snowplow-enrich-output/enriched/archive/run=" + strftime("%Y-%m-%d") +r"-\d{2}-\d{2}-\d{2}/")
try:
s3.download_file(Bucket=os.environ.get('SP_BUCKET'), Key=s3_filename, Filename=local_filename)
except Exception as e:
logger.error("%s - Could not retrieve %s because: %s" % ("download_s3_file()", s3_filename, e))
raise
class process_sp_data(process_raw_snowplow_event_data):
def run(self):
s3_filename = "part_%s.%s.json.gz" % (self.file_root, (self.dataset_date + timedelta(days=1)).strftime("%Y-%m-%d"))
infile_name = self.download_s3_file(s3_filename)
match_files = self.list_files(os.environ.get('SP_BUCKET'))
with gzip.open(self.output().path, "wb") as outfile:
with gzip.open(infile_name, "rb") as infile:
for line in infile:
try:
indict = json.loads(line)
except Exception as e:
logger.warn("s -Could not parse line: %s =%s" % (self.__class__.__name__, e, line))
continue
outdict = indict
错误是:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/luigi/worker.py", line 199, in run
new_deps = self._run_get_new_deps()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/luigi/worker.py", line 139, in _run_get_new_deps
task_gen = self.task.run()
File "target.py", line 123, in run
infile_name = self.download_s3_file(s3_filename)
TypeError: download_s3_file() missing 1 required positional argument: 's3_filename'
即使我已经通过了争论,为什么这仍然行不通?谢谢您的帮助。
答案 0 :(得分:4)
您已指定@staticmethod
,所以self
不是隐式对象参数。因此,当您致电:
self.download_s3_file(s3_filename)
s3_filename
设置为self
,并且...缺少一个参数
删除self
或@staticmethod
@staticmethod
def download_s3_file(s3_filename):
或
def download_s3_file(self, s3_filename):
如果您未在方法中使用self
,则它是静态的,因此请选择第一个选项
答案 1 :(得分:0)
您的参数丢失并且被设置为SIGPIPE
,因为您将方法定义为self
,因此,如果要将方法保持为@staticmethod
,请删除self
< / p>