_________________________ TestUpload.test_png_chunked __________________________ self = <tests.upload_tests.TestUpload testMethod=test_png_chunked> def test_png_chunked(self): """Test uploading a png in two chunks using Site.upload.""" page = pywikibot.FilePage(self.site, 'MP_sounds-pwb-chunked.png') self.site.upload(page, source_filename=self.sounds_png, comment='pywikibot test', > ignore_warnings=True, chunk_size=1024) tests/upload_tests.py:46: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ pywikibot/site/_decorators.py:93: in callee return fn(self, *args, **kwargs) pywikibot/site/_apisite.py:3023: in upload return Uploader(self, filepage, **kwargs).upload() pywikibot/site/_upload.py:134: in upload return self._upload(self.ignore_warnings, self.report_success) pywikibot/site/_upload.py:439: in _upload report_success, file_key) pywikibot/site/_upload.py:457: in submit result = request.submit()['upload'] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = pywikibot.data.api._requests.Request<wikipedia:test->'/w/api.php?action=upload&text=pywikibot+test&filename=MP+sounds-...y=1azs4b3xr4ng.yzvhgu.23124.png&ignorewarnings=&maxlag=5&format=json&token=f71d55ad3eaf00649aefe1e64ffecf3c666939bd+\'> def submit(self) -> dict: """Submit a query and parse the response. .. versionchanged:: 8.0.4 in addition to *readapidenied* also try to login when API response is *notloggedin*. .. versionchanged:: 9.0 Raise :exc:`exceptions.APIError` if the same error comes twice in a row within the loop. :return: a dict containing data retrieved from api.php """ self._add_defaults() use_get = self._use_get() retries = 0 self.last_error = dict.fromkeys(['code', 'info']) while True: paramstring = self._http_param_string() simulate = self._simulate(self.action) if simulate: return simulate if self.throttle: self.site.throttle(write=self.write) else: pywikibot.log( f"Submitting unthrottled action '{self.action}'.") use_get, uri, body, headers = self._get_request_params(use_get, paramstring) response, use_get = self._http_request(use_get, uri, body, headers, paramstring) if response is None: continue result = self._json_loads(response) if result is None: continue if self._userinfo_query(result): continue if self._handle_warnings(result): continue if 'error' not in result: return result error = result['error'] for key in result: if key in ('error', 'warnings'): continue assert key not in error error[key] = result[key] if '*' in error: # help text returned error['help'] = error.pop('*') code = error.setdefault('code', 'Unknown') info = error.setdefault('info', None) if (code == self.last_error['code'] and info == self.last_error['info']): raise pywikibot.exceptions.APIError(**self.last_error) self.last_error = error if not self._logged_in(code): continue if code == 'maxlag': retries += 1 if retries > max(5, pywikibot.config.max_retries): break pywikibot.log('Pausing due to database lag: ' + info) try: lag = error['lag'] except KeyError: lag = lagpattern.search(info) lag = float(lag['lag']) if lag else 0.0 self.site.throttle.lag(lag * retries) # reset last error self.last_error = dict.fromkeys(['code', 'info']) continue if code == 'help' and self.action == 'help': # The help module returns an error result with the complete # API information. As this data was requested, return the # data instead of raising an exception. return {'help': {'mime': 'text/plain', 'help': error['help']}} pywikibot.warning(f'API error {code}: {info}') pywikibot.log(f' headers=\n{response.headers}') if self._internal_api_error(code, error.copy(), result): continue # Phab. tickets T48535, T64126, T68494, T68619 if code == 'failed-save' \ and self._is_wikibase_error_retryable(error): self.wait() continue if code == 'ratelimited': self._ratelimited() continue # If notloggedin or readapidenied is returned try to login if code in ('notloggedin', 'readapidenied') \ and self.site._loginstatus in (LoginStatus.NOT_ATTEMPTED, LoginStatus.NOT_LOGGED_IN): self.site.login() continue if self._bad_token(code): continue if 'mwoauth-invalid-authorization' in code: msg = f'OAuth authentication for {self.site}: {info}' if 'Nonce already used' in info: pywikibot.error(f'Retrying failed {msg}') continue raise NoUsernameError(f'Failed {msg}') if code == 'cirrussearch-too-busy-error': # T170647 self.wait() continue if code in ('search-title-disabled', 'search-text-disabled'): prefix = 'gsr' if 'gsrsearch' in self._params else 'sr' del self._params[prefix + 'what'] # use intitle: search instead if code == 'search-title-disabled' \ and self.site.has_extension('CirrusSearch'): key = prefix + 'search' self._params[key] = ['intitle:' + search for search in self._params[key]] continue if code == 'urlshortener-blocked': # T244062 # add additional informations to error dict error['current site'] = self.site if self.site.user(): error['current user'] = self.site.user() else: # not logged in; show the IP uinfo = self.site.userinfo error['current user'] = uinfo['name'] # raise error try: param_repr = str(self._params) pywikibot.log( f'API Error: query=\n{pprint.pformat(param_repr)}') pywikibot.log(f' response=\n{result}') args = {'param': body} if body else {} args.update(error) > raise pywikibot.exceptions.APIError(**args) E pywikibot.exceptions.APIError: fileexists-no-change: The upload is an exact duplicate of the current version of [[:File:MP sounds-pwb-chunked.png]]. E [param: action=upload&text=pywikibot+test&filename=MP+sounds-pwb-chunked.png&comment=pywikibot+test&assert=user&filekey=1azs4b3xr4ng.yzvhgu.23124.png&ignorewarnings=&maxlag=5&format=json&token=f71d55ad3eaf00649aefe1e64ffecf3c666939bd%2B%5C; E stasherrors: [{'message': 'uploadstash-exception', 'params': ['UploadStashBadPathException', "Path doesn't exist."], 'code': 'uploadstash-exception', 'type': 'error'}]; E servedby: mw-api-ext.eqiad.main-778c97d8cb-knmxd; E help: See https://test.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes.] pywikibot/data/api/_requests.py:1122: APIError
Description
Description
Status | Subtype | Assigned | Task | ||
---|---|---|---|---|---|
Open | None | T152961 Improve tests suite | |||
Open | None | T129368 Usages of unittest.expectedFailure or unittest.skip should be solved (goal) | |||
Open | None | T367260 Write test CI github action has ~ 22 failing tests or errors | |||
Open | None | T367320 TestUpload.test_png_chunked() of upload_tests fails with duplicate error |