The digg_url in session.get is obviously None, but in fact, what I want to use is the above if...else statement. If in c, just declare digg_url above the if statement, but py cannot do this. Do.
Of course, to solve my problem, I can move session.get into the if statement, but if I think about it, what if there are dozens of statements like session.get that reference digg_url?
So I want to ask how to solve this problem? (Can it only be set to global? I’m a bit speechless about this py)
You can directly use variables defined in if-else in Python
For example
Yours
session.get
中的digg_url
不应该是None
, you can export it and take a look.Although I'm not very familiar with python, maybe it's possible to assign an arbitrary value to digg_url before the if?
You can define on if
Or use the ternary operator
It is recommended that you print out digg_url and session before using get. I think your logic is wrong. And what are the four and two parameter headers in get used for?