Xqt created this task.
Xqt added projects: Pywikibot, Pywikibot-Wikidata, Wikidata.
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper.
TASK DESCRIPTION
**Steps to replicate the issue**:
I changed the last statements of http.fetch() as follows (adding print
statements and disabled encoding):
try:
# Note that the connections are pooled which mean that a future
# HTTPS request can succeed even if the certificate is invalid and
# verify=True, when a request with verify=False happened before
response = session.request(method, uri,
headers=headers, auth=auth,
timeout=timeout,
**kwargs)
except Exception as e:
response = e
else:
pass
# response.encoding = _decide_encoding(response, charset) ## ignore
encodings
for callback in callbacks:
callback(response)
from pprint import pprint ## added some prints
pprint(response.json())
pprint(response.text)
pprint(response.content)
return response
and started these statements:
import pywikibot
site = pywikibot.Site('wikidata')
result = site.parsevalue('quantity', ['1.90e-9+-0.20e-9'], {}, False)
**What happens?**:
I always got:
https://www.wikidata.org/w/api.php?action=wbparsevalue&datatype=quantity&values=1.90e-9%2B-0.20e-9&options=%7B%7D&maxlag=5&format=json
{'results': [{'raw': '1.90e-9+-0.20e-9',
'type': 'quantity',
'value': {'amount': '+0.000000190',
'lowerBound': '+0.000000170',
'unit': '1',
'upperBound': '+0.000000210'}}]}
'{"results":[{"raw":"1.90e-9+-0.20e-9","value":{"amount":"+0.000000190","unit":"1","upperBound":"+0.000000210","lowerBound":"+0.000000170"},"type":"quantity"}]}'
(b'{"results":[{"raw":"1.90e-9+-0.20e-9","value":{"amount":"+0.000000190","unit'
b'":"1","upperBound":"+0.000000210","lowerBound":"+0.000000170"},"type":"quant'
b'ity"}]}')
even I cleared the cache. This means the the raw bytes content coming from
wiki is wrong alread and text as well json() decoded it right. This is the
bytes response (from above):
(b'{"results":[{"raw":"1.90e-9+-0.20e-9","value":{"amount":"+0.000000190","unit'
b'":"1","upperBound":"+0.000000210","lowerBound":"+0.000000170"},"type":"quant'
b'ity"}]}')
**What should have happened instead?**:
'amount' value should be smaller by factor 100:
{'results': [{'raw': '1.90e-9+-0.20e-9',
'type': 'quantity',
'value': {'amount': '+0.00000000190',
'lowerBound': '+0.000000170',
'unit': '1',
'upperBound': '+0.000000210'}}]}
A direct api call from the uri given above did it right:
uri is
https://www.wikidata.org/w/api.php?action=wbparsevalue&datatype=quantity&values=1.90e-9%2B-0.20e-9&options=%7B%7D&maxlag=5&format=jsonfm
and the result is:
{
"results": [
{
"raw": "1.90e-9+-0.20e-9",
"value": {
"amount": "+0.00000000190",
"unit": "1",
"upperBound": "+0.00000000210",
"lowerBound": "+0.00000000170"
},
"type": "quantity"
}
]
}
**Software version** :
D:\>python
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
D:\>pip freeze
certifi==2019.6.16
chardet==3.0.4
idna==2.8
mwparserfromhell==0.6.4
requests==2.22.0
urllib3==1.25.3
setuptools==57.0.0
I also checked it with these packages:
D:\>pip freeze
certifi==2019.6.16
chardet==3.0.4
idna==2.8
regex==2022.7.9
requests==2.22.0
urllib3==1.25.3
wcwidth==0.2.5
wikitextparser==0.47.4
setuptools==57.0.0
**Other information**:
It worked with Python 3.7.3 and the (last) packages given above.
TASK DETAIL
https://phabricator.wikimedia.org/T312755
EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/
To: Xqt
Cc: Aklapper, pywikibot-bugs-list, Xqt, Astuthiodit_1, karapayneWMDE,
Invadibot, Jyoo1011, maantietaja, JohnsonLee01, SHEKH, Dijkstra, ItamarWMDE,
Khutuck, Akuckartz, Zkhalido, Viztor, Nandana, Wenyi, Lahi, Gq86,
GoranSMilovanovic, QZanden, Tbscho, MayS, LawExplorer, Mdupont, JJMC89,
Dvorapa, _jensen, rosalieper, Altostratus, Avicennasis, Scott_WUaS, mys_721tx,
Wikidata-bugs, aude, jayvdb, Ricordisamoa, Masti, Alchimista, Mbch331
_______________________________________________
pywikibot-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]