-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scrapy/Parsel type of response issue. #275
Comments
You could pin the parsel version? |
@Laerte sure, we can pin it. But the question is still there in |
>>> from parsel import Selector
>>> text = '{"isValidAddress": "1"}'
>>> selector = Selector(text=text)
>>> selector.type
'json' |
@Gallaecio thanks, Also, I am just pointing out that the new version break compatibility and makes it harder to maintain edge cases in Scrapy MW. |
I agree that it is not a backward-compatible change. However, I think the new behavior makes sense, and is somewhat coherent with how Scrapy handles e.g. calling The previous behavior of silently failing could waste developer time during debugging. For cases where there was HTML embedded in the JSON and before |
@Gallaecio I think it is worth adding about the non backward-compatible change to the https://github.com/scrapy/parsel/releases/tag/v1.8.0 |
This note should be on History under 1.8.0 version release notes right? What you think about this text:
|
@Gallaecio >>> s = Selector(text='1')
>>> s.type
'json'
>>> s
Traceback (most recent call last):
File "parsel/utils.py", line 89, in shorten
if len(text) <= width:
TypeError: object of type 'int' has no len() |
I would consider To force a text interpretation (which feels pointless for Parsel) you could do: >>> s = Selector(text='1', type="text")
>>> s.type
'text'
>>> s
<Selector query=None data='1'> Which has its own bug, Alternatively you could force its interpretation as a (JSON) string using >>> s = Selector(root='1')
>>> s.type
'json'
>>> s
<Selector query=None data='1'> Note though that in both cases, >>> s.get()
'1' |
@wRAR Can i raise a PR to always cast the from parsel import Selector
s = Selector(text='true')
print(s) |
@Laerte I think it makes sense to cast self.get() instead of modifying shorten() |
@wRAR Make sense, since shorten already expect a string right? diff --git a/parsel/selector.py b/parsel/selector.py
index 8d884a4..4285ee3 100644
--- a/parsel/selector.py
+++ b/parsel/selector.py
@@ -749,7 +749,7 @@ class Selector:
Percent encoded content is unquoted.
"""
if self.type in ("text", "json"):
- return self.root
+ return str(self.root)
try:
return typing.cast(
str |
I was thinking about |
Hello guys. I am using
Scrapy
and code in the MW has broken because of newparsel
version. Could you suggest best practice how to get type of the response in the MW, please?parsel == 1.6.0
parsel == 1.8.1
The text was updated successfully, but these errors were encountered: