Hướng dẫn python get request query params - python nhận được yêu cầu tham số truy vấn

Tôi không thực sự chắc chắn những gì tôi đang làm. Tôi có nên sử dụng một thư viện cho việc này không? Hay làm nó bằng tay?

Vì vậy, tôi đang cố gắng thực hiện một số công việc với API Withings (http://www.withings.com/api) trong Python.

Để thực hiện một số yêu cầu, xác thực OAuth là bắt buộc. Tôi đã trải qua bằng cách sử dụng thư viện yêu cầu và nhận được mã thông báo OAuth và Bí mật, cùng với mã thông báo bí mật tiêu dùng và người tiêu dùng của tôi.

Bây giờ tôi đang ở điểm phải đưa ra yêu cầu và tôi đang gặp phải một số vấn đề. Định dạng cho yêu cầu tôi cần thực hiện như sau (một ví dụ từ API của họ):

http://wbsapi.withings.net/notify?action=subscribe
&callbackurl=http%3a%2f%2fwww.yourdomain.net%2fyourCustomApplication.php
&comment=Your%20Own%20Application%20Description
&oauth_consumer_key=c331c571585e7c518c78656f41582e96fc1c2b926cf77648223dd76424b52b
&oauth_nonce=accbac1b7ee2b86b828e6dc4a5a539b2
&oauth_signature=XfobZMboIg2cRyNKAvyzONHHnKM%3D
&oauth_signature_method=HMAC-SHA1
&oauth_timestamp=1311842514
&oauth_token=887557411788d5120537c6550fbf2df68921f8dd6f8c7e7f9b441941eb10
&oauth_version=1.0
&userid=831

Theo như tôi có thể nói, đây là một định dạng điển hình với OAuth, ngoại trừ người dùng ở cuối.

Vì vậy, tôi có thể đưa ra yêu cầu như thế này bằng thư viện yêu cầu không? Hoặc một số thư viện khác? Làm thế nào để tôi có được URL đúng, với các trường bình luận và userid và callbackurl? Hay tôi cần phải tạo URL này bằng tay? Nếu đó là trường hợp, cách tốt nhất để làm việc này?

Bất kỳ hỗ trợ nào cũng được đánh giá rất cao, vì tôi đã bị mắc kẹt trong một thời gian.

CHỈNH SỬA

Vì vậy, để làm rõ, tôi hiểu khoảng 98% mã tôi đang được đề cập. Cuối cùng tôi chỉ gặp một vấn đề nhỏ.

Vì vậy, tôi đang ở đây, với mã sau:

from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)

Đây là tất cả những gì tôi cần. Tôi có mọi thứ tôi cần nhưng chữ ký. Có cách nào tôi có thể nhận được chữ ký từ các thư viện OAuth không? Đây là tất cả những gì đã giữ tôi lên.

Chuỗi truy vấn là gì? Làm thế nào để tôi sử dụng chúng? Trong bài học này, bạn sẽ học chính xác điều đó. Hàm .get() chấp nhận đối số params, có thể là một từ điển, một danh sách các bộ dữ liệu hoặc byte thô. Ví dụ sau sử dụng API tìm kiếm GitHub đang tìm kiếm thư viện requests:

>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>

00:00 Này, Chào mừng bạn đến với Phần 2. Chúng tôi sẽ bắt đầu tiếp theo với việc nói về các tham số chuỗi truy vấn, sau đó chúng tôi sẽ tiếp tục yêu cầu các tiêu đề, các phương thức HTTP khác, thân thông báo và sau đó kiểm tra yêu cầu của bạn. Vì vậy, các tham số chuỗi truy vấn là gì? Chà, họ là một phần của URL gán các giá trị để chỉ định các tham số. Hey, welcome to Section 2. We’re going to get started next with talking about query string parameters, then we’ll continue on to request headers, other HTTP methods, the message body, and then inspecting your request. So, what are query string parameters? Well, they’re the part of the URL which assigns values to specify parameters.

00:19 Họ thường được thêm vào cơ sở của URL, giống như trong ví dụ này, nơi chúng tôi đang tìm kiếm kho lưu trữ. Nó bắt đầu với dấu hỏi (?), và sau đó bạn có thể thấy một truy vấn được thêm vào. They’re commonly added to the base of the URL, like in this example where we’re searching repositories. It starts with the question mark (?), and then you can see a query added.

00:29 Các ví dụ khác nếu bạn nhớ chúng tôi quay lại .content từ API REST gốc, đây là một số cặp đó. Một là commit_search_url, và ở đây bạn có thể thấy nó nói về việc tìm kiếm trong các cam kết. Other examples—if you remember us returning back our .content from the Root Rest API, here are some of those pairs. One was commit_search_url, and here you can see it talking about searching within the commits.

00:41 Một người khác sẽ là tìm kiếm người dùng và user_search_url bắt đầu với các tham số của nó ở đây, ngay sau ____10. Các tham số chuỗi truy vấn có thể bao gồm một loạt các đối số. Another would be to search for users, and the user_search_url starts with its parameters here, just after

from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
0. Query string parameters can be composed of a series of arguments.

00:53 Sê -ri được phân tách bằng dấu cộng (

from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
1). Vì vậy, hãy để thử nó. Quay trở lại trình soạn thảo của chúng tôi ở đây, chúng tôi sẽ tạo một tệp mới. Tôi chỉ đơn giản là gọi nó là
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
2.
The series is separated by a plus sign (
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
1). So, let’s try it out. Back in our editor here, we’re going to create a new file. I’m simply going to call it
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
2.

01:09 Vì vậy, chúng tôi sẽ chuyển một chuỗi truy vấn vào API tìm kiếm GitHub tại đây. Vì vậy, hãy để bắt đầu bằng cách nhập requests. Cho mình một số phòng. So, we’re going to pass a query string into GitHub’s Search API here. So, let’s start by importing requests. Give myself some room.

01:24 Được rồi. Chúng tôi sẽ thực hiện một biến

from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
4 và thực hiện yêu cầu
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
5 vào đó. Trong trường hợp cụ thể này, chúng tôi đã đặt vào
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
6 làm tham số đầu tiên và sau đó chúng tôi có thể thêm các tham số bổ sung. Hãy bắt đầu với điều đó.
All right. We’re going to make a
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
4 variable and do a
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
5 request into it. In this particular case, we’d put in the
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
6 as a first parameter, and then we can add additional parameters. Let’s start with that.

01:42 Vì vậy, trong trường hợp này, chúng tôi sẽ nói params (tham số). Chúng tôi sẽ làm chúng như một từ điển. Nó chỉ có một, nhưng khóa của khóa sẽ là

from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
8, giá trị là chúng tôi đang tìm kiếm
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
9 và chúng tôi sẽ thêm một đối số thứ hai là
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
0.
So in this case, we’re going to say params (parameters). We’ll do them as a dictionary. It’s only one, but… The key will be
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
8, the value is we’re searching for
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
9, and we’ll add a second argument of
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
0.

02:00 Chúng tôi sẽ thoát khỏi các dòng bổ sung này và xuống dưới cùng ở đây, chúng tôi sẽ kiểm tra một số thuộc tính từ kho lưu trữ. Chúng tôi sẽ tạo một biến khác với phản hồi JSON. We’ll get rid of these extra lines, and down at the bottom here we’ll inspect some attributes from the repository. We’ll make another variable with the JSON response.

02:12 Lấy đối tượng

from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
4 của chúng tôi, hãy quay lại dưới dạng JSON, và sau đó chúng tôi sẽ tạo một đối tượng kho lưu trữ sẽ từ đó
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
2.
Take our
from __future__ import unicode_literals
from urlparse import parse_qs
import requests
from requests_oauthlib import OAuth2Session

consumer_key = '**Valid consumer key**'

consumer_secret = '**Valid consumer secret**'


oauth_key = '**Valid oauth key obtained through requests library and OAuth workflow**'

oauth_secret ='**Valid oauth secret obtained through requests library and OAuth workflow**'

verifier = '**Valid consumer key obtained through requests library and OAuth workflow**'

base_url = 'http://wbsapi.withings.net/notify'

params = {
'action': 'subscribe',
'callbackurl': '**callback URL**',
'comment': '**comment**',
'oauth_consumer_key': '**consumer_key**',
'oauth_nonce': 'etc etc',
'oauth_signature' : '' # <-------------- Where do I get this
# etc etc... I have everything else
}
r = requests.get("http://wbsapi.withings.net/notify", params=params)
4 object, have it come back as JSON, and then we’ll make a repository object that will be from that
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
2.

02:24 Vì nó là một từ điển, chúng tôi sẽ lấy khóa

>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
3 và giá trị đầu tiên của nó. Giống như một tìm kiếm trên Google, bạn có may mắn không? Chúng tôi sẽ tìm thấy mục đầu tiên trong tìm kiếm của chúng tôi. Since it’s a dictionary, we’ll pull the
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
3 key and its very first value. Like a Google search—are you lucky?—we’re going to find the very first item in our search.

02:38 Và từ đó đối tượng

>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
4 mà Lừa được trả lại, chúng tôi sẽ sử dụng một vài chìa khóa ở đây, một trong số đó là
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
5, và sau đó thứ hai là chúng tôi sẽ rút lại
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
6 và in chúng ra bằng cách sử dụng F-String. Một lần nữa, chỉ cần một lưu ý: bạn sẽ cần Python 3.6 trở lên để sử dụng chúng.
And from that
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
4 object that’s being returned back, we’ll use a couple of keys here—one being the
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
5, and then the second being we’ll pull back the
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
6 and print them out using f-strings. Again, just a note: you will need Python 3.6 or higher to use these.

02:58 Vì vậy, hãy để Lôi lưu và để cho chạy nó. So, let’s save and let’s run it.

03:06 Nó tìm kiếm ngay bây giờ. Được rồi! Đây là những gì nó trở lại. Tên kho lưu trữ là requests! Chính xác những gì chúng tôi đang tìm kiếm, vì vậy chúng tôi đã có một cú hích tốt. Và nó đã in ra mô tả, mô tả là

>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
8. It’s searching right now. All right! Here is what it returned back. The repository name is requests! Exactly what we were looking for, so we got a good hit. And it printed out the description, the description being
>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
8.

03:22 Chúng tôi có thể sửa đổi nó một chút, cố gắng tìm kiếm một kho lưu trữ khác. We could modify it a little bit, try to search a different repository.

03:27 Hãy nói rằng chúng tôi đang tìm kiếm ____ 29 và có lẽ chúng tôi biết .get()0 là một tham số. Hãy để lưu lại điều đó và thử lại. Let’s say we’re searching for

>>> requests.get(
...     'https://api.github.com/search/repositories',
...     params={'q': 'requests+language:python'}
... )
<Response [200]>
9… and maybe we know the .get()0 as a parameter. Let’s save that and try again.

03:47 Vì vậy, kho lưu trữ đó được đặt tên là .get()1. .get()2. Tuyệt quá! So, that repository is named .get()1. .get()2. Great!

Làm thế nào để bạn có được các tham số truy vấn trong Python?

Phân tích chuỗi truy vấn URL để nhận các tham số truy vấn trong Python #..
Nhập các phương thức URLPARE và PARSE_QS từ Urllib.Mô -đun phân tích cú pháp ..
Sử dụng phương thức UrlParse để có được một đối tượng kết quả phân tích ..
Chuyển đối tượng cho phương thức pARSE_QS để lấy từ điển của các thông số truy vấn ..

Chúng tôi có thể gửi các tham số truy vấn trong yêu cầu nhận được không?

Trừ khi có một cái gì đó nhạy cảm trong các tham số yêu cầu, việc gửi chúng là một phần của URL là hoàn toàn tốt..

Làm thế nào bạn có thể chụp các thông số truy vấn được gửi bởi phương thức nhận?

Các tham số truy vấn của bạn có thể được truy xuất từ đối tượng truy vấn trên đối tượng yêu cầu được gửi đến tuyến đường của bạn.Nó ở dạng một đối tượng mà bạn có thể truy cập trực tiếp các tham số truy vấn mà bạn quan tâm.Trong trường hợp này, Express xử lý tất cả các phân tích cú pháp URL cho bạn và phơi bày các tham số được truy xuất như đối tượng này.. It is in the form of an object in which you can directly access the query parameters you care about. In this case Express handles all of the URL parsing for you and exposes the retrieved parameters as this object.

Làm cách nào để nhận được tham số yêu cầu?

Chỉ cần nhìn vào getAttribution (tên chuỗi) hoặc getParameter (tên chuỗi).getAttribute(String name) or getParameter(String name) .